是什么导致了 ImportError:在 os X 上升级 Python 后没有名为 pkg_resources 的模块?

发布于 2024-08-12 02:23:13 字数 1403 浏览 4 评论 0原文

我刚刚将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

遗心遗梦遗幸福 2024-08-19 02:23:13

我遇到了同样的ImportError。不知何故,setuptools 包已在我的 Python 环境中被删除。

要解决此问题,请运行 setuptools 的安装脚本:

curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python

如果您有任何版本的 分发,或任何低于 0.6 的 setuptools,您必须先卸载它。*

请参阅安装说明了解更多详细信息。


* 如果您已经有一个可用的 distribute,将其升级到“兼容性包装器”以切换到 setuptools 会更容易。但如果事情已经坏了,就不要尝试这样做。

I encountered the same ImportError. Somehow the setuptools package had been deleted in my Python environment.

To fix the issue, run the setup script for setuptools:

curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python

If you have any version of distribute, or any setuptools 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 to setuptools is easier. But if things are already broken, don't try that.

青衫儰鉨ミ守葔 2024-08-19 02:23:13

[更新] TL;DR pkg_resourcesDistribute安装工具

[更新 2] 正如 PyCon 2013 上宣布的那样,Distributesetuptools 项目已重新合并。 Distribute 现已弃用,您应该只使用新的当前 setuptools。试试这个:

curl -O https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
python ez_setup.py

或者,更好的是,使用当前的 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_installpkg_resources 模块也会通过此步骤自动安装。

然后使用新安装的 easy_install 版本(或 pip)来安装 ipython

easy_install ipython

或者

pip install 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 and setuptools projects have re-merged. Distribute is now deprecated and you should just use the new current setuptools. Try this:

curl -O https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
python ez_setup.py

Or, better, use a current pip as the high level interface and which will use setuptools 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, typing python2.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 install easy_install using setuptools following the instructions there. The pkg_resources module is also automatically installed by this step.

Then use the newly-installed version of easy_install (or pip) to install ipython.

easy_install ipython

or

pip install ipython

It should automatically get installed to the correct site-packages location for that python instance and you should be good to go.

生死何惧 2024-08-19 02:23:13

如果在 mac os 10.7 上升级 python 并且 pkg_resources 不起作用,解决此问题的最简单方法就是重新安装 setuptools,如 Ned 上面提到的。

sudo pip install setuptools --upgrade
or sudo easy_install install setuptools --upgrade

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.

sudo pip install setuptools --upgrade
or sudo easy_install install setuptools --upgrade
难以启齿的温柔 2024-08-19 02:23:13

在我的系统(OSX 10.6)上,该软件包位于

/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py

我希望可以帮助您确定它是否丢失或不在您的路径上。

On my system (OSX 10.6) that package is at

/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py

I hope that helps you figure out if it's missing or just not on your path.

如痴如狂 2024-08-19 02:23:13

原因可能是因为 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.

鹿港巷口少年归 2024-08-19 02:23:13

我意识到这与 OSX 无关,但在嵌入式系统(Beagle Bone Angstrom)上我收到了完全相同的错误消息。安装以下 ipk 包解决了这个问题。

opkg install python-setuptools
opkg install python-pip

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.

opkg install python-setuptools
opkg install python-pip
嘿咻 2024-08-19 02:23:13

我在 Ubuntu 上遇到此错误,以下方法对我有用:

删除 dropbox 二进制文件并通过运行再次下载它们:

sudo rm -rf /var/lib/dropbox/.dropbox-dist
dropbox start -i

I got this error on Ubuntu, and the following worked for me:

Removed the dropbox binaries and download them again, by running:

sudo rm -rf /var/lib/dropbox/.dropbox-dist
dropbox start -i
茶底世界 2024-08-19 02:23:13

当我从事高速公路相关项目时,我遇到了同样的问题。

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

苍白女子 2024-08-19 02:23:13

就我而言,缺少包 python-pygments 。 可以通过命令修复:

sudo apt-get install python-pygments

如果pandoc有问题, 您应该安装 pandocpandoc-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 install pandoc and pandoc-citeproc.

sudo apt-get install pandoc pandoc-citeproc

放低过去 2024-08-19 02:23:13

仅当您可以卸载 python 时才尝试此操作。

我使用卸载了 python

brew uninstall python

,然后使用安装了

brew install python

python ,然后它就工作了!

Try this only if you are ok with uninstalling python.

I uninstalled python using

brew uninstall python

then later installed using

brew install python

then it worked!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文