gpt4 book ai didi

python - 如何将 PyInstaller 包含在 PyInstaller 包中?

转载 作者:行者123 更新时间:2023-12-02 02:08:11 26 4
gpt4 key购买 nike

我想要卡住一个 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 似乎并未将自身捆绑在应用程序内。有一个issue在 PyInstaller github 页面上,但它并没有真正帮助。这可能吗?如果是这样,怎么办?

这需要在 Windows 10 和 Python 3.7 上运行。我使用的是 PyInstaller 版本 3.5。

最佳答案

来自 PyInstaller 开发人员之一:

To do this you'd need a hook for PyInstaller - we don't have one and won't create one. You'd also need to mod the bootloader process, create runtime hooks, and loads more. We can't, won't and don't support or encourage this.

TL;DR:使用 PyInstaller 无法做到这一点,一种解决方法是使用其他软件,例如 nuitkaPyoxidizerEmbed your app manually .

关于python - 如何将 PyInstaller 包含在 PyInstaller 包中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58755392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com