python - pyinstaller导入错误: No module named pkg_resources

标签 python setuptools pyinstaller

我正在尝试使用 Pyinstaller 打包我的 Python 脚本。我的脚本导入了第三方模块 Exscript 和 Netaddr。当我尝试运行 Pyinstaller 生成的可执行文件时出现以下错误。

我知道“pkg_resources”指的是 setuptools,但我检查了一下,站点包下有 setuptools 18.2,我在脚本目录中看到了 easy install。我正在运行 Python 2.7。

感谢任何帮助 Pyinstaller 工作的帮助。仅供引用,我在这里搜索并查看了类似的问题,但它们不适用于这个特定问题。

这是运行 Pyinstaller 的输出(我只包括了错误):

C:\Python27\Lib\PyInstaller-2.1>pyinstaller c:\users\<username>\pycharmprojects\neworking2\network_login.py
5759 INFO: building because out00-Tree.toc missing or bad
5983 INFO: building because out01-Tree.toc missing or bad
7097 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing
9569 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing
9591 INFO: rebuilding out00-EXE.toc because network_login.exe missing

执行Pyinstaller生成的.exe输出结果:

 C:\Python27\Lib\PyInstaller-2.1\network_login\dist\network_login>network_loginTraceback (most recent call last):
File "build\bdist.win32\egg\paramiko\__init__.py", line 30, in <module>
File "build\bdist.win32\egg\paramiko\transport.py", line 49, in <module>
File "build\bdist.win32\egg\paramiko\dsskey.py", line 26, in <module>
File "build\bdist.win32\egg\Crypto\PublicKey\DSA.py", line 89, in <module>
File "build\bdist.win32\egg\Crypto\Random\__init__.py", line 28, in <module>
File "build\bdist.win32\egg\Crypto\Random\OSRNG\__init__.py", line 34, in <module>
File "build\bdist.win32\egg\Crypto\Random\OSRNG\nt.py", line 28, in <module>
File "build\bdist.win32\egg\Crypto\Random\OSRNG\winrandom.py", line 7, in <module>
File "build\bdist.win32\egg\Crypto\Random\OSRNG\winrandom.py", line 3, in __bootstrap__ImportError: No module named pkg_resources

最佳答案

只需将其导入为:

import pkg_resources.py2_warn

在主文件中。

关于python - pyinstaller导入错误: No module named pkg_resources,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32639699/

相关文章:

python - 在设置关键字参数的默认值时可以引用位置参数吗?

python - 使用 setuptools 通过 Python 库安装的数据文件位置

python - 为什么 Pandas read_excel 函数在 Pyinstaller .exe 中返回错误,但在 Python 解释器下却没有?

python - 使用 Swagger 生成的新代码更新 Flask 代码

python - 是否有任何理由使用 pass in有利而不是 None 作为空语句

python - setuptools:包数据文件夹位置

具有多个函数的 Python C 扩展

python - 在 Windows 7 中使用 Pyinstaller 创建的 Exe 在 xp 和 linux 中不起作用

python - 阻止 Pyinstaller 复制不需要的/不必要的文件和文件夹

python - TensorFlow 估计器混淆矩阵