【发布时间】:2017-11-23 07:42:11
【问题描述】:
我正在尝试从我的代码中创建一个使用 PyQt5 的可执行文件。我正在使用 Python 3.5.3 -64 位,在 Windows 10 中开发,并使用 pip 安装 pyinstaller 3.2.1。
我这样运行 pyinstaller:
pyinstaller.exe --onefile --windowed main.py
我收到导入错误:
File "C:\Python35\Scripts\pyinstaller-script.py", line 11, in <module> load_entry_point('PyInstaller==3.2.1', 'console_scripts', 'pyinstaller')()
File "C:\Python35\lib\site-packages\pkg_resources\__init__.py", line 565, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "C:\Python35\lib\site-packages\pkg_resources\__init__.py", line 2631, in load_entry_point
return ep.load()
File "C:\Python35\lib\site-packages\pkg_resources\__init__.py", line 2291, in load
return self.resolve()
File "C:\Python35\lib\site-packages\pkg_resources\__init__.py", line 2297, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "C:\Python35\lib\site-packages\PyInstaller\__main__.py", line 21, in <module>
import PyInstaller.building.build_main
File "C:\Python35\lib\site-packages\PyInstaller\building\build_main.py", line 32, in <module>
from ..depend import bindepend
File "C:\Python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 38, in <module>
from ..utils.win32.winmanifest import RT_MANIFEST
File "C:\Python35\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", line 97, in <module>
from PyInstaller.utils.win32 import winresource
File "C:\Python35\lib\site-packages\PyInstaller\utils\win32\winresource.py", line 20, in <module>
import pywintypes
File "C:\Python35\lib\site-packages\win32\lib\pywintypes.py", line 124, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Python35\lib\site-packages\win32\lib\pywintypes.py", line 64, in __import_pywin32_system_module__
import _win32sysloader
ImportError: DLL load failed: The specified module could not be found.
我读到这意味着 pip 没有安装 pywin32,我需要安装这个 Microsoft Visual Package:https://www.microsoft.com/en-us/download/details.aspx?id=5555。我下载并安装了它,但我得到了同样的错误。
编辑:
从 sourceforge.net/projects/pywin32/files/pywin32/Build%20221 安装 pywin32 后,导入错误消失了,但我在运行时收到警告(输出长达数百行,这是一个 sn -p):
pyinstaller main.py
....
3220 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of C:\Python35\python.exe
3251 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of C:\Python35\python.exe
3267 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of C:\Python35\python.exe
3305 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of C:\Python35\python.exe
3336 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of C:\Python35\python.exe
....
9265 WARNING: lib not found: Qt5Core.dll dependency of C:\Python35\lib\site-packages\PyQt5\Qt\plugins\imageformats\qgif.dll
9297 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of C:\Python35\lib\site-packages\PyQt5\Qt\plugins\imageformats\qgif.dll
9333 WARNING: lib not found: Qt5Gui.dll dependency of C:\Python35\lib\site-packages\PyQt5\Qt\plugins\imageformats\qgif.dll
9366 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of C:\Python35\lib\site-packages\PyQt5\Qt\plugins\imageformats\qgif.dll
然后我运行:
pyinstaller main.spec
并得到类似的警告。生成的 exe 文件立即关闭。
【问题讨论】:
-
尝试在没有窗口的情况下运行它或改用规范文件
-
在没有窗口的情况下运行它不起作用。规范文件是什么?
-
运行
pyinstaller file.py然后创建一个名为file.spec的文件 -
使用spec文件而不是python文件
pyinstaller file.spec -
它创建了一个文件夹,但显示了很多警告。当我运行它创建的应用程序时,它会立即关闭。
标签: python pyqt python-3.5 pyqt5 pyinstaller