【发布时间】:2019-11-07 19:03:04
【问题描述】:
我想冻结一个 Python 应用程序,它的功能之一是能够使用 PyInstaller 生成冻结的 Python 应用程序。这是一个显示我想要实现的目标的最小应用程序:
import PyInstaller.__main__
with open('inception', 'w', encoding='utf-8') as f:
f.write('import sys; print("Hello from the inside")\n')
PyInstaller.__main__.run(['--noconfirm', '--onedir', 'inception'])
用 PyInstaller 冻结它
PS> pyinstaller --noconfirm --onedir example.py
应该产生一个可执行的exemple.exe,可以执行它来产生inception.exe。
在第一次尝试时,我收到以下错误
PS> .\dist\example\example.exe
PyInstaller cannot check for assembly dependencies.
Please install pywin32-ctypes.
pip install pywin32-ctypes
已通过安装 pywin32(pywin32-ctypes 已安装)并更改 PyInstaller 的 compat.py 文件来解决此问题,如 here 所述。现在重新捆绑应用程序会导致以下错误
PS> .\dist\example\example.exe
Traceback (most recent call last):
File "example.py", line 2, in <module>
import PyInstaller.__main__
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "d:\code\stackoverflow\pyinstaller_inception\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\PyInstaller\__init__.py", line 66, in <module>
File "lib\site-packages\pkg_resources\__init__.py", line 481, in get_distribution
File "lib\site-packages\pkg_resources\__init__.py", line 357, in get_provider
File "lib\site-packages\pkg_resources\__init__.py", line 900, in require
File "lib\site-packages\pkg_resources\__init__.py", line 786, in resolve
pkg_resources.DistributionNotFound: The 'PyInstaller' distribution was not found and is required by the application
[14376] Failed to execute script example
所以看起来 PyInstaller 并没有将自己捆绑在应用程序中。 PyInstaller github 页面上有一个issue,但它并没有真正的帮助。这甚至可能吗?如果有,怎么做?
这需要在 Windows 10 和 Python 3.7 上运行。我正在使用 PyInstaller 3.5 版。
【问题讨论】:
-
链接的问题不是关于在 PyInstaller 包中包含 PyInstaller。
标签: python windows pyinstaller