Pyinstaller生成的exe无法正常工作

时间:2018-10-09 20:09:42

标签: python python-3.x tkinter pyinstaller

我正在尝试打包我编写的Python程序/脚本(pastebin link),其中包括使用tkinter模块的GUI。我决定使用Pyinstaller,根据他们的说法,它支持Python 3.7。

当前,尝试运行pyinstaller似乎在实际打包时不会产生任何问题。在尝试运行可执行文件之后,它失败了。我生成一个可执行文件的一个文件变体,它只是打开命令提示符并挂起。当我执行非一个文件命令时,它会立即打开和关闭,但是会给出错误输出,由于关闭速度如此之快,我看不到它。我直接在cmd中打开可执行文件以解决该问题,这给了我这个错误:

C:\Users\mqian\Desktop\CGIProject\autoprimercode\windowsversion\build\windowsaut
oprimer>windowsautoprimer.exe
Error loading Python DLL 'C:\Users\mqian\Desktop\CGIProject\autoprimercode\windo
wsversion\build\windowsautoprimer\python37.dll'.
LoadLibrary: The specified module could not be found.

我不知道它是否应该在此文件夹中查找python37.dll,但是,我有一个绝妙的主意,可以通过跟踪将dll中的dll复制到指定的dll目录中(显然,它应该不必那样)。现在我得到的错误是:

C:\Users\mqian\Desktop\CGIProject\autoprimercode\windowsversion\build\windowsaut
oprimer>windowsautoprimer.exe
Traceback (most recent call last):
  File "site-packages\PyInstaller\loader\rthooks\pyi_rth__tkinter.py", line 28,
in <module>
FileNotFoundError: Tcl data directory "C:\Users\mqian\Desktop\CGIProject\autopri
mercode\windowsversion\build\windowsautoprimer\tcl" not found.
[6600] Failed to execute script pyi_rth__tkinter

无休止的谷歌搜索没有产生任何具体的结果。以下是一些我认为可能会有所帮助的相关链接。

https://github.com/pyinstaller/pyinstaller/issues/2149

https://www.xoolive.org/2015/09/09/issues-on-loading-dlls-with-pyinstaller.html

PyInstaller: "No module named Tkinter"

https://github.com/pyinstaller/pyinstaller/issues/2495

Error loading python27.dll error for pyinstaller

这是我拥有的规格文件:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['windowsautoprimer.py'],
             pathex=['C:\\Users\\mqian\\Desktop\\CGIProject\\autoprimercode\\windowsversion'],
             binaries=[],
             datas=[],
             hiddenimports=['tkinter', 'Tkinter'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='windowsautoprimer',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='windowsautoprimer')

2 个答案:

答案 0 :(得分:1)

遇到相同的问题,但随后意识到我无意间尝试执行build文件夹而不是dist文件夹中的文件。

看起来您可能在追溯中犯了同样的错误,因此请查看在dist中使用可执行文件是否不能为您解决

答案 1 :(得分:0)

请在命令中使用- onefile 选项重新创建exe。它不会要求您提供python37.dll

相关问题