当从简单的Python脚本创建可执行文件时,Pyinstaller成功完成。但是,当尝试运行可执行文件时,它会在ModuleNotFoundError中失败。
Traceback...
ModuleNotFoundError: No module named 'git'
[26228] Failed to execute script xyz我通过Pipenv安装了gitpython。为什么没有正确地捆绑呢?
发布于 2019-12-21 22:07:51
@vauhochzett提供的答案几乎是正确的,但需要作如下修改。不要使用pipenv中的pip来安装pyinstaller,而是使用pipenv本身来安装pyinstaller。
这意味着您需要在您创建的每个pipenv中安装pyinstaller,但是它将为您使用的每个venv正确地排序导入路径。
当使用pip安装pyinstaller时,导入路径会有些不稳定,但是当pipenv用于在venv中安装模块时,一切都按预期的方式工作,如下所示。
$ pipenv install pyinstaller
$ pipenv run pyinstaller script.spec发布于 2018-10-11 13:44:18
这里一个可能的问题是使用全局Pyinstaller安装。此安装不知道Pipenv下载的pip包。
我在Pipenv弹壳里又试了一次,效果很好:
pipenv shell
pip install pyinstaller
pyinstaller script.py -F现在,模块已正确绑定。
编辑:,我刚刚了解到我的答案并不完全正确。Aarion的accepted answer修复了我的错误。
https://stackoverflow.com/questions/52761655
复制相似问题