简体   繁体   English

Pyinstaller 生成的 exe 无法正常工作

[英]Pyinstaller generated exe doesn't work properly

I'm trying to package a python program/script ( pastebin link ) I wrote which includes a GUI using the tkinter module.我正在尝试打包我编写的 python 程序/脚本( pastebin 链接),其中包含使用 tkinter 模块的 GUI。 I decided to use Pyinstaller and according to them it supports Python 3.7.我决定使用 Pyinstaller,据他们说它支持 Python 3.7。

Currently, trying to run pyinstaller seems to generate no issues when actually packaging.目前,尝试运行 pyinstaller 在实际打包时似乎不会产生任何问题。 It is after when I try to run the executable that it fails.在我尝试运行可执行文件之后,它失败了。 One I generate a one file variant of the executable, it simply opens a command prompt and hangs.一个我生成可执行文件的一个文件变体,它只是打开一个命令提示符并挂起。 When I do the non one file command, it opens and closes immediately, but gives an error output which I can't see due to how quick it closes.当我执行非一个文件命令时,它会立即打开和关闭,但会给出错误输出,由于关闭速度太快,我看不到该输出。 I opened up the executable directly in the cmd to get around that, and it gives me this error:我直接在 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.

I don't know if it's supposed to be looking for the python37.dll in this folder, but nevertheless, I had the bright idea to copy the dll from the python directory into the specified one by the trace (obviously it shouldn't have to be like that).我不知道它是否应该在这个文件夹中寻找 python37.dll,但是,我有一个好主意,将 dll 从 python 目录复制到跟踪指定的一个(显然它不应该有变成那样)。 And now the error I get is this:现在我得到的错误是这样的:

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

An endless amount of googling hasn't yielded anything concrete.无休止的谷歌搜索并没有产生任何具体的结果。 Here are some relevant links that I thought might help.以下是一些我认为可能会有所帮助的相关链接。

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

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

PyInstaller: "No module named Tkinter" PyInstaller:“没有名为 Tkinter 的模块”

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

Error loading python27.dll error for pyinstaller 为pyinstaller加载python27.dll错误时出错

and here's the specfile I have:这是我拥有的规范文件:

# -*- 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')

Had the same issue but then realized that I was inadvertently trying to execute the file in the build folder instead of the dist folder.遇到了同样的问题,但后来意识到我无意中尝试在build文件夹而不是dist文件夹中执行文件。

Looks like you might be making the same mistake from your traceback so see if using the executable in dist doesn't fix it for you看起来您可能在回溯中犯了同样的错误,所以看看在dist中使用可执行文件是否不能为您修复它

Please recreate the exe with -- onefile option in command.请在命令中使用--onefile选项重新创建 exe。 It wont ask you for python37.dll它不会要求你提供 python37.dll

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM