是什么导致了 ImportError:在 os X 上升级 Python 后没有名为 pkg_resources 的模块?
我刚刚将 Mac 上的 Python 更新到 2.6.4。 我是从 dmg 包安装的。
二进制文件似乎没有正确设置我的 Python 路径,因此我在 .bash_profile
中添加了 '/usr/local/lib/python2.6/site-packages'
>>> pprint.pprint(sys.path)
['',
'/Users/Bryan/work/django-trunk',
'/usr/local/lib/python2.6/site-packages',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages']
显然,不是所有必需的路径,因为我无法运行 iPython。
$ ipython
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named `pkg_resources`
我已经完成了 Google 搜索,但我无法真正弄清楚如何安装 pkg_resources
或确保它位于路径上。
我需要做什么来解决这个问题?
I just updated Python to 2.6.4 on my Mac.
I installed from the dmg package.
The binary did not seem to correctly set my Python path, so I added '/usr/local/lib/python2.6/site-packages'
in .bash_profile
>>> pprint.pprint(sys.path)
['',
'/Users/Bryan/work/django-trunk',
'/usr/local/lib/python2.6/site-packages',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages']
Apparently that is not all the required paths because I can't run iPython.
$ ipython
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named `pkg_resources`
I've done Google searches and I can't really figure out how to install pkg_resources
or make sure it's on the path.
What do I need to do to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我遇到了同样的
ImportError
。不知何故,setuptools
包已在我的 Python 环境中被删除。要解决此问题,请运行
setuptools
的安装脚本:如果您有任何版本的
分发
,或任何低于 0.6 的setuptools
,您必须先卸载它。*请参阅安装说明了解更多详细信息。
* 如果您已经有一个可用的
distribute
,将其升级到“兼容性包装器”以切换到setuptools
会更容易。但如果事情已经坏了,就不要尝试这样做。I encountered the same
ImportError
. Somehow thesetuptools
package had been deleted in my Python environment.To fix the issue, run the setup script for
setuptools
:If you have any version of
distribute
, or anysetuptools
below 0.6, you will have to uninstall it first.*See Installation Instructions for further details.
* If you already have a working
distribute
, upgrading it to the "compatibility wrapper" that switches you over tosetuptools
is easier. But if things are already broken, don't try that.[更新] TL;DR
pkg_resources
由 Distribute 或安装工具。[更新 2] 正如 PyCon 2013 上宣布的那样,
Distribute
和setuptools
项目已重新合并。Distribute
现已弃用,您应该只使用新的当前setuptools
。试试这个:或者,更好的是,使用当前的
pip
作为最高价level 接口,它将在幕后使用setuptools
。[针对OP特定问题的较长答案]:
您没有在问题中说,但我假设您是从Apple提供的Python(10.5上的2.5或10.6上的2.6.1)升级的,或者是从python.org升级的Python 2.5。在任何这些情况下,重要的一点是每个 Python 实例都有自己的库,包括自己的站点包库,这是安装其他包的地方。 (顺便说一句,默认情况下它们都不使用
/usr/local/lib
。)这意味着您需要安装新的 python 2.6 所需的附加软件包。最简单的方法是首先确保新的 python2.6 首先出现在您的搜索$PATH
上(也就是说,输入python2.6
会按预期调用它) ; python2.6安装程序应该修改您的.bash_profile
,将其框架bin目录放在$PATH
的前面。然后按照此处的说明使用 setuptools 安装easy_install
。pkg_resources
模块也会通过此步骤自动安装。然后使用新安装的
easy_install
版本(或pip
)来安装ipython
。或者
它应该自动安装到该 python 实例的正确
site-packages
位置,您应该可以开始了。[UPDATE] TL;DR
pkg_resources
is provided by either Distribute or setuptools.[UPDATE 2] As announced at PyCon 2013, the
Distribute
andsetuptools
projects have re-merged.Distribute
is now deprecated and you should just use the new currentsetuptools
. Try this:Or, better, use a current
pip
as the high level interface and which will usesetuptools
under the covers.[Longer answer for OP's specific problem]:
You don't say in your question but I'm assuming you upgraded from the Apple-supplied Python (2.5 on 10.5 or 2.6.1 on 10.6) or that you upgraded from a python.org Python 2.5. In any of those cases, the important point is that each Python instance has its own library, including its own site-packages library, which is where additional packages are installed. (And none of them use
/usr/local/lib
by default, by the way.) That means you'll need to install those additional packages you need for your new python 2.6. The easiest way to do this is to first ensure that the new python2.6 appears first on your search$PATH
(that is, typingpython2.6
invokes it as expected); the python2.6 installer should have modified your.bash_profile
to put its framework bin directory at the front of$PATH
. Then installeasy_install
using setuptools following the instructions there. Thepkg_resources
module is also automatically installed by this step.Then use the newly-installed version of
easy_install
(orpip
) to installipython
.or
It should automatically get installed to the correct
site-packages
location for that python instance and you should be good to go.如果在 mac os 10.7 上升级 python 并且 pkg_resources 不起作用,解决此问题的最简单方法就是重新安装 setuptools,如 Ned 上面提到的。
In case of upgrading your python on mac os 10.7 and pkg_resources doesn't work, the simplest way to fix this is just reinstall setuptools as Ned mentioned above.
在我的系统(OSX 10.6)上,该软件包位于
我希望可以帮助您确定它是否丢失或不在您的路径上。
On my system (OSX 10.6) that package is at
I hope that helps you figure out if it's missing or just not on your path.
原因可能是因为 IPython 模块不在您的 PYTHONPATH 中。
如果你下载 IPython 然后执行
python setup.py install
安装程序不会将模块 IPython 添加到您的 python 路径中。
您可能需要手动将其添加到 PYTHONPATH 中。它应该在您执行以下操作后起作用:
export PYTHONPATH=/pathtoIPython:$PYTHONPATH
在 .bashrc 或 .profile 中添加此行以使其永久。
The reason might be because the IPython module is not in your PYTHONPATH.
If you donwload IPython and then do
python setup.py install
The setup doesn't add the module IPython to your python path.
You might want to add it to your PYTHONPATH manually. It should work after you do :
export PYTHONPATH=/pathtoIPython:$PYTHONPATH
Add this line in your .bashrc or .profile to make it permanent.
我意识到这与 OSX 无关,但在嵌入式系统(Beagle Bone Angstrom)上我收到了完全相同的错误消息。安装以下 ipk 包解决了这个问题。
I realize this is not related to OSX, but on an embedded system (Beagle Bone Angstrom) I had the exact same error message. Installing the following ipk packages solved it.
我在 Ubuntu 上遇到此错误,以下方法对我有用:
删除 dropbox 二进制文件并通过运行再次下载它们:
I got this error on Ubuntu, and the following worked for me:
Removed the dropbox binaries and download them again, by running:
当我从事高速公路相关项目时,我遇到了同样的问题。
1)所以我下载了 setuptools.-0.9.8.tar.gz 形式 https:// /pypi.python.org/packages/source/s/setuptools/ 并提取它。
2)然后我获取 pkg_resources 模块并将其复制到需要的文件夹中。
**在我的例子中,该文件夹是 C:\Python27\Lib\site-packages\autobahn
I encountered with the same problem when i am working on autobahn related project.
1) So I download the setuptools.-0.9.8.tar.gz form https://pypi.python.org/packages/source/s/setuptools/ and extract it.
2 )Then i get the pkg_resources module and copy it to the folder where it needed.
**in my case that folder was C:\Python27\Lib\site-packages\autobahn
就我而言,缺少包
python-pygments
。 可以通过命令修复:sudo apt-get install python-pygments
。如果
pandoc
有问题, 您应该安装pandoc
和pandoc-citeproc
。sudo apt-get install pandoc pandoc-citeproc
In my case, package
python-pygments
was missed. You can fix it by command:sudo apt-get install python-pygments
If there is problem with
pandoc
. You should installpandoc
andpandoc-citeproc
.sudo apt-get install pandoc pandoc-citeproc
仅当您可以卸载 python 时才尝试此操作。
我使用卸载了 python
,然后使用安装了
python ,然后它就工作了!
Try this only if you are ok with uninstalling python.
I uninstalled python using
then later installed using
then it worked!