从使用Tix的Python代码生成.exe文件

2024-10-01 11:29:32 发布

您现在位置:Python中文网/ 问答频道 /正文

最近,我在Github上发现了一个我经常使用的程序代码(Pikasav),因为我最近学习了Python语法,所以决定把它派生出来练习Python,并实现一些使它更容易/更好地使用的特性。在

在实现了一个特性之后,我试图使用py2exe生成一个.exe文件,但是由于找不到Tix模块,它没有工作。我试着复制提示.py在我的工作目录里,也没用。在

之后,我决定尝试PyInstaller,因为我认为在设置.py文件,而且它似乎更容易使用。但是,由于同样的原因,它也不起作用,这显然意味着问题不是来自py2exe配置。在

以下是PyInstaller的输出,尽管我认为它没有那么有用:

C:\Users\Afonso\Documents\Side Projects\PikaSav>PyInstaller --onefile pikasav.py
1421 INFO: PyInstaller: 3.1.1
1421 INFO: Python: 2.7.11
1421 INFO: Platform: Windows-10-10.0.10240
1421 INFO: wrote C:\Users\Afonso\Documents\Side Projects\PikaSav\pikasav.spec
1421 INFO: UPX is not available.
1437 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Afonso\\Documents\\Side Projects\\PikaSav',
 'C:\\Users\\Afonso\\Documents\\Side Projects\\PikaSav']
1437 INFO: checking Analysis
1437 INFO: Building Analysis because out00-Analysis.toc is non existent
1437 INFO: Initializing module dependency graph...
1452 INFO: Initializing module graph hooks...
1530 INFO: running Analysis out00-Analysis.toc
1657 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
  required by C:\Python27\python.exe
1780 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_60a5df56e60dc5df.manifest
1796 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest
1796 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_f47f259ef656232a.manifest
1873 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.9158_none ...
1873 INFO: Found manifest C:\WINDOWS\WinSxS\Manifests\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc.manifest
1889 INFO: Searching for file msvcr90.dll
1889 INFO: Found file C:\WINDOWS\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc\msvcr90.dll
1889 INFO: Searching for file msvcp90.dll
1889 INFO: Found file C:\WINDOWS\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc\msvcp90.dll
1889 INFO: Searching for file msvcm90.dll
1889 INFO: Found file C:\WINDOWS\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc\msvcm90.dll
1967 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_60a5df56e60dc5df.manifest
1967 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest
1967 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_f47f259ef656232a.manifest
1967 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9158)
2514 INFO: Analyzing C:\Users\Afonso\Documents\Side Projects\PikaSav\pikasav.py
4889 INFO: Looking for import hooks ...
4905 INFO: Processing hook   hook-_tkinter.py
5077 INFO: checking Tree
5077 INFO: Building Tree because out00-Tree.toc is non existent
5092 INFO: Building Tree out00-Tree.toc
5338 INFO: checking Tree
5338 INFO: Building Tree because out01-Tree.toc is non existent
5339 INFO: Building Tree out01-Tree.toc
5389 INFO: Processing hook   hook-encodings.py
7202 INFO: Looking for ctypes DLLs
7202 INFO: Analyzing run-time hooks ...
7202 INFO: Including run-time hook 'pyi_rth__tkinter.py'
7217 INFO: Looking for dynamic libraries
7530 INFO: Looking for eggs
7530 INFO: Using Python library C:\WINDOWS\system32\python27.dll
7530 INFO: Found binding redirects:
[BindingRedirect(name=u'Microsoft.VC90.CRT', language=None, arch=u'x86', oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 9158), publicKeyToken=u'1fc8b3b9a1e18e3b')]
7546 INFO: Warnings written to C:\Users\Afonso\Documents\Side Projects\PikaSav\build\pikasav\warnpikasav.txt
7827 INFO: checking PYZ
7827 INFO: Building PYZ because out00-PYZ.toc is non existent
7827 INFO: Building PYZ (ZlibArchive) C:\Users\Afonso\Documents\Side Projects\PikaSav\build\pikasav\out00-PYZ.pyz
8062 INFO: checking PKG
8062 INFO: Building PKG because out00-PKG.toc is non existent
8062 INFO: Building PKG (CArchive) out00-PKG.pkg
8280 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9158)
16608 INFO: Bootloader C:\Python27\lib\site-packages\pyinstaller-3.1.1-py2.7.egg\PyInstaller\bootloader\Windows-32bit\run.exe
16608 INFO: checking EXE
16608 INFO: Building EXE because out00-EXE.toc is non existent
16608 INFO: Building EXE from out00-EXE.toc
16702 INFO: appending archive to EXE C:\Users\Afonso\Documents\Side Projects\PikaSav\dist\pikasav.exe

这是warnpikasav.txt内容,在上面的输出中提到。在

^{pr2}$

他们中没有一个人以任何方式提到蒂克斯——至少我已经找到了。我也知道,从我的搜索,Tix有点旧,但它是程序使用的,我不想改变它,因为作者最初是这样做的。他还设法为程序生成了一个.exe文件,这样不仅意味着它是可能的,而且我可能在这里做错了什么。在

提前谢谢。在


Tags: infononetreewindowsusersx86microsoftbuilding
2条回答

这是我在Py2EXE中使用的一个通用setup.py

from distutils.core import setup
import os
import shutil
import py2exe

data_files = []
setup(
    name='ApplicationName',
    console=['Application.py'], # 'windows' means it's a GUI, 'console' It's a console program, 'service' a Windows' service, 'com_server' is for a COM server
    # You can add more and py2exe will compile them separately.
    options={ # This is the list of options each module has, for example py2exe, but for example, PyQt or django could also contain specific options
        'py2exe': {
            'packages': [],
            'dist_dir': 'dist', # The output folder
            'compressed': True, # If you want the program to be compressed to be as small as possible
            'includes': ['tix', 'os', 'logging', 'yaml', 'sqlalchemy', 'pymysql'], # All the modules you need to be included, This is where you put the package that is failing to be founhd. so if you import something inside main.py which also imports something, it might break.
        }
    },

    data_files=data_files # Finally, pass any data files

)

好吧,我似乎找到了答案。在比较python目录中的文件和生成的文件后,我发现问题是py2exe出于某种原因没有从Tix复制文件。在

在那之后,我决定再次搜索并再次找到this页面,并注意到我的Tix版本与示例中的版本不同,只是修改了脚本以匹配我的版本,使其完美地工作。在

脚本如下:

import glob
import os
import sys
from distutils.core import setup
import py2exe

def files(folder):
    for path in glob.glob(folder+'/*'):
        if os.path.isfile(path):
            yield path

data_files=[
            ('.', glob.glob(sys.prefix+'/DLLs/tix84*.dll')),
            ('tcl/tix8.4.3', files(sys.prefix+'/tcl/tix8.4.3/')),
            ('tcl/tix8.4.3/bitmaps', files(sys.prefix+'/tcl/tix8.4.3/bitmaps/')),
            ('tcl/tix8.4.3/pref', files(sys.prefix+'/tcl/tix8.4.3/pref/')),
           ]

setup(
      script_args=['py2exe'],
      windows=['pikasav.py'],
      data_files=data_files,
     )

如果你将来碰巧遇到这个问题,并且有一个不同的Tix版本,记住在需要的时候改变它。现在我需要找到一种方法,使文件数量最少,但这是完全不同的情况。在

相关问题 更多 >