Python Error : No module named pkg_resources
Python Error : No module named pkg_resources
我想在 MacOS 上使用 Python3.7
我已经 Python 2.7 版本了。
我在 .bash_profile
、alias python="/usr/local/bin/python3.7"
和 source ~/.bash_profile
上创建了一个别名。
所以我把Python2.7删到/usr/local/lib/
现在,当我尝试执行 pip install PySide2
时,出现错误:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 6, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
我认为这个错误发生在我删除 Python2.7
之后
有人可以帮我解决我的错误吗?
谢谢!
这是因为 setuptools 包损坏造成的,您只需重新安装即可。
对于大多数操作系统:pip install setuptools
Linux: apt-get install python-setuptools
或 yum install python-setuptools
pyinstaller 3.6 与 python 3.7.* 上的 setuptools 45.1.0 不兼容,应降级为 45.0.0
pip install setuptools==45.0.0
也可以用 passing/adding hidden_imports 'pkg_resources.py2_warn' 固定到 pyinstaller spec
此处跟踪问题和解决方案:https://github.com/pypa/setuptools/issues/1963
我从 here 中找到了解决方案。
在我的例子中,我从以下目录打开 hook-pkg_resources.py 文件:
~/.local/lib/python3.6/site-packages/PyInstaller/hooks/
之后我添加了这行代码:
hiddenimports.append('pkg_resources.py2_warn')
这两行代码之间:
hiddenimports = collect_submodules('pkg_resources._vendor')
和
excludedimports = ['__main__']
之后,我再次 运行 PyInstaller,生成的可执行文件运行良好。
在搜索此错误代码时首先在 google 上偶然发现了这个答案,因此为了将来参考,我只留下 link 解决了我的问题:
tldr:
pyinstaller --hidden-import=pkg_resources.py2_warn example.py
我想在 MacOS 上使用 Python3.7
我已经 Python 2.7 版本了。
我在 .bash_profile
、alias python="/usr/local/bin/python3.7"
和 source ~/.bash_profile
上创建了一个别名。
所以我把Python2.7删到/usr/local/lib/
现在,当我尝试执行 pip install PySide2
时,出现错误:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 6, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
我认为这个错误发生在我删除 Python2.7
之后有人可以帮我解决我的错误吗?
谢谢!
这是因为 setuptools 包损坏造成的,您只需重新安装即可。
对于大多数操作系统:pip install setuptools
Linux: apt-get install python-setuptools
或 yum install python-setuptools
pyinstaller 3.6 与 python 3.7.* 上的 setuptools 45.1.0 不兼容,应降级为 45.0.0
pip install setuptools==45.0.0
也可以用 passing/adding hidden_imports 'pkg_resources.py2_warn' 固定到 pyinstaller spec
此处跟踪问题和解决方案:https://github.com/pypa/setuptools/issues/1963
我从 here 中找到了解决方案。
在我的例子中,我从以下目录打开 hook-pkg_resources.py 文件:
~/.local/lib/python3.6/site-packages/PyInstaller/hooks/
之后我添加了这行代码:
hiddenimports.append('pkg_resources.py2_warn')
这两行代码之间:
hiddenimports = collect_submodules('pkg_resources._vendor')
和
excludedimports = ['__main__']
之后,我再次 运行 PyInstaller,生成的可执行文件运行良好。
在搜索此错误代码时首先在 google 上偶然发现了这个答案,因此为了将来参考,我只留下 link 解决了我的问题:
tldr:
pyinstaller --hidden-import=pkg_resources.py2_warn example.py