我使用 pyinstaller 创建了一个 exe(我使用的是 python 3.7.6 和 pyinstaller 3.6)
pyinstaller --onefile --icon=icon.ico my_script.py
(即使
pyinstaller --onedir --icon=icon.ico my_script.py
问题也是一样的)该 exe 构建良好,但我在此过程中遇到多个错误:
25484 INFO: Excluding import 'PyQt5'
25486 INFO: Removing import of PyQt5 from module PIL.ImageQt
25487 INFO: Import to be excluded not found: 'FixTk'
25488 INFO: Excluding import 'tkinter'
25490 INFO: Removing import of tkinter from module PIL.ImageTk
25491 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
25496 INFO: Excluding import 'tkinter'
25498 INFO: Import to be excluded not found: 'FixTk'
25499 INFO: Loading module hook "hook-pkg_resources.py"...
26227 INFO: Processing pre-safe import module hook win32com
26524 INFO: Excluding import '__main__'
26525 INFO: Removing import of __main__ from module pkg_resources
尽管存在这些错误,但 exe 在某些计算机上可以正常工作,而在某些计算机上则不能。它不起作用的地方我在启动时收到此错误:
Traceback (most recent call last):
File "my_script.py", line 39, in <module>
File "c:\users\valerio\appdata\local\programs\python\python37-32\lib\site-pack
ages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
File "site-packages\cv2\__init__.py", line 3, in <module>
ImportError: DLL load failed: The specified module could not be found.
[2800] Failed to execute script my_script
所以我的问题是:
谢谢你
最佳答案
我找到了我的问题的答案。我把它写在这里以防有人需要。
问题出在 Windows Server 2008 和 2012 上。他们缺少一个名为“桌面体验”的模块。
一旦安装它(例如使用 this 指南),错误就会消失。
另一个类似的discussion
关于python - 来自 pyinstaller 的 python 可执行文件的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60903252/