Python Pyinstaller“无法执行脚本pyi_rth_pkgres”和缺少包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37815371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pyinstaller "Failed to execute script pyi_rth_pkgres" and missing packages
提问by gurnben
This is my first time posting a question here as most of my questions have already been answered by someone else! I am working on a GUI application in python and am attempting to use pyinstaller to package it into a single folder and .exe for easier portability. Currently, I am using windows 10 and anaconda3 to manage my python packages. The application relies on tkinter, pillow, numpy, scikit-learn, opencv, ffmpeg, and matplotlib. The application is formatted with a main GUI.py file that creates objects of a number of other files (many of which are stored in a subfolder as this GUI is replacing a command line utility that served the same purpose). The issue I am running into (as you can see in the title) is that the .exe is throwing the error block:
这是我第一次在这里发布问题,因为我的大部分问题已经被其他人回答了!我正在使用 python 开发 GUI 应用程序,并尝试使用 pyinstaller 将其打包到单个文件夹和 .exe 中,以便于移植。目前,我使用 windows 10 和 anaconda3 来管理我的 python 包。该应用程序依赖于 tkinter、pillow、numpy、scikit-learn、opencv、ffmpeg 和 matplotlib。该应用程序使用一个主 GUI.py 文件进行格式化,该文件创建了许多其他文件的对象(其中许多文件存储在子文件夹中,因为此 GUI 正在替换用于相同目的的命令行实用程序)。我遇到的问题(如您在标题中所见)是 .exe 抛出错误块:
Traceback (most recent call last): File "site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py", line 11, in File "c:\users\gurnben\anaconda3\envs\opencv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "site-packages\setuptools-20.7.0-py3.5.egg\pkg_resources__init__.py", line 68, in File "site-packages\setuptools-20.7.0-py3.5.egg\pkg_resources\extern__init__.py", line 60, in load_module ImportError: The 'packaging' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution. Failed to execute script pyi_rth_pkgres
回溯(最近一次调用):文件“site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py”,第 11 行,在文件“c:\users\gurnben\anaconda3\envs\opencv\lib\site-packages\”中PyInstaller\loader\pyimod03_importers.py”,第 389 行,在 load_module exec(bytecode, module. dict) 文件“site-packages\setuptools-20.7.0-py3.5.egg\pkg_resources__init__.py”,第 68 行,在文件中"site-packages\setuptools-20.7.0-py3.5.egg\pkg_resources\extern__init__.py", line 60, in load_module ImportError: The 'packaging' package is required; 通常这与此软件包捆绑在一起,因此如果您收到此警告,请咨询您的发行版的打包人员。无法执行脚本 pyi_rth_pkgres
When I look at the warn.txt it gives a massive list of missing packages including parts of some packages that are actually in the single folder package.
I have, however, successfully gotten it to recognize the dll files from opencv and it is not listed among the missing (nor is ffmpeg however I did not see any ffmpeg files in the folder). I had to pass in a custom path to get it to include the opencv files as they are not in anaconda at this time.
当我查看warn.txt 时,它给出了大量丢失包的列表,其中包括一些实际上位于单个文件夹包中的包的一部分。
但是,我已经成功地让它识别了来自 opencv 的 dll 文件,并且它没有被列在缺失的列表中(ffmpeg 也没有列出,但是我在文件夹中没有看到任何 ffmpeg 文件)。我必须传入一个自定义路径以使其包含 opencv 文件,因为它们此时不在 anaconda 中。
Any hints or ideas for next troubleshooting steps? I am overly greatful for all of the help you an offer and I can upload any code, files, etc. that would help you diagnose the issue. In the meantime I will continue searching for a solution myself!
下一步故障排除步骤的任何提示或想法?我非常感谢您提供的所有帮助,我可以上传任何代码、文件等,以帮助您诊断问题。与此同时,我将继续自己寻找解决方案!
回答by crifan
same problem here:
同样的问题在这里:
- OS: Win10
- Python: 3.7
pyinstaller
installed bypip install pyinstaller
- 操作系统:Win10
- 蟒蛇:3.7
pyinstaller
安装者pip install pyinstaller
fix by (same solution with above, by no need download):
修复(与上述相同的解决方案,无需下载):
pip uninstall pyinstaller
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
回答by Anirudh
Extending Vikash Kumar's
answer, build the application by adding the --hidden-import argument to the command
.
扩展Vikash Kumar's
答案,通过添加--hidden-import argument to the command
.
For example, running the command given below worked for me.
例如,运行下面给出的命令对我有用。
"pyinstaller --hidden-import=pkg_resources.py2_warn example.py"
"pyinstaller --hidden-import=pkg_resources.py2_warn example.py"
update: added missing "="
更新:添加缺少的“=”
回答by Vikash Kumar
Adding the line:
添加行:
import pkg_resources.py2_warn
to my code helped.
对我的代码有帮助。
回答by sas
I had the same problem. Was solved by reinstalling the pyinstaller with the developer's branch version, following the directions in: https://github.com/pyinstaller/pyinstaller/issues/2137
我有同样的问题。已通过使用开发人员的分支版本重新安装 pyinstaller 解决,按照以下说明操作:https: //github.com/pyinstaller/pyinstaller/issues/2137
The steps are:
步骤是:
- Remove PyInstaller
pip uninstall pyinstaller
. - Download the zip from github.
- Unzip file.
- Make sure you are in the directory with "setup.py" and run:
python setup.py install
- 删除 PyInstaller
pip uninstall pyinstaller
。 - 从github下载 zip 。
- 解压缩文件。
- 确保您在带有“setup.py”的目录中并运行:
python setup.py install
回答by Stepan Rogonov
I extend @vikash-kumar answer.
pyinstaller toolhas command line parameter --hidden-import
.
我扩展@vikash-kumar answer。
pyinstaller 工具有命令行参数--hidden-import
。
It resolves the topic problem for me.
它为我解决了主题问题。
More information:
https://pythonhosted.org/PyInstaller/when-things-go-wrong.html#listing-hidden-imports.
更多信息:
https : //pythonhosted.org/PyInstaller/when-things-go-wrong.html#listing-hidden-imports。