首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在PyInstaller包中包含PyInstaller?

如何在PyInstaller包中包含PyInstaller?
EN

Stack Overflow用户
提问于 2019-11-08 03:03:04
回答 1查看 363关注 0票数 3

我想冻结一个Python应用程序,它的一个特性是能够使用PyInstaller生成冻结的Python应用程序。下面是一个最小的应用程序,展示了我想要实现的目标:

代码语言:javascript
复制
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冻结这一切

代码语言:javascript
复制
PS> pyinstaller --noconfirm --onedir example.py

应该生成一个可以执行以生成inception.exe的可执行exemple.exe

在第一次尝试时,我得到了以下错误

代码语言:javascript
复制
PS> .\dist\example\example.exe
PyInstaller cannot check for assembly dependencies.
Please install pywin32-ctypes.

pip install pywin32-ctypes

通过安装pywin32 (已经安装了pywin32-ctypes)并按照here的说明更改PyInstaller的compat.py文件,修复了此问题。重新捆绑应用程序现在会导致以下错误

代码语言:javascript
复制
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,但它并没有真正的帮助。这有可能吗?如果是这样的话,是怎么做的?

这需要在装有Python 3.7的Windows10上运行。我使用的是PyInstaller 3.5版。

EN

回答 1

Stack Overflow用户

发布于 2020-03-03 18:53:51

从其中一个PyInstaller开发人员:

要做到这一点,你需要一个PyInstaller的钩子--我们没有,也不会创建一个。您还需要修改引导加载器进程,创建运行时挂钩,以及加载更多内容。我们不能,不会,也不会支持或鼓励这样做。

你不能用PyInstaller做到这一点,一种解决办法是使用另一种软件,如nuitkaPyoxidizerEmbed your app manually

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58755392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档