python - 从 python 生成的独立 *.exe 不可运行
问题描述
虽然通过命令“pyinstaller --onefile filename.py”可以成功完成从*.py-到独立*.exe文件的转换,但可执行文件本身无法运行
Traceback(最近一次调用最后):文件“venv\Lib\site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py”,第 13 行,在文件“c:\users\user01\pycharmprojects\api4trd\venv\lib\ site-packages\PyInstaller\loader\pyimod03_importers.py”,第 623 行,在 exec_module exec(bytecode, module. dict ) 文件“lib\site-packages\pkg_resources__init__.py”,第 86 行,在 ModuleNotFoundError 中:没有名为 'pkg_resources 的模块.py2_warn' [13560] 无法执行脚本 pyi_rth_pkgres
使用以下软件包
1) 数学
2) 日期时间
3) yfinance
Python版本:3.8.1
pyinstaller 版本:3.6
操作系统:W10
谢谢!
解决方案
您的 pyinstaller 命令中缺少一个隐藏的导入。虽然早期版本的 Python 和 Pyinstaller 从来没有使用过这个错误,但是这里是解决方案
pyinstaller --onefile --hidden-import=pkg_resources.py2_warn filename.py