Python easy_install 在 Mac OS X 上令人困惑

Python easy_install 在 Mac OS X 上令人困惑

环境信息:

$ which python
/usr/bin/python
$ python
Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin

$ echo $PATH
/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/X11R6/bin:/opt/local/bin:/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:~/.utility_scripts

$ which easy_install
/usr/bin/easy_install

具体来说,让我们尝试 simplejson 模块(我知道它与 2.6 中的 import json 相同,但这不是重点)

$ sudo easy_install simplejson
Searching for simplejson
Reading http://pypi.python.org/simple/simplejson/
Reading http://undefined.org/python/#simplejson
Best match: simplejson 2.1.0
Downloading http://pypi.python.org/packages/source/s/simplejson/simplejson-2.1.0.tar.gz#md5=3ea565fd1216462162c6929b264cf365
Processing simplejson-2.1.0.tar.gz
Running simplejson-2.1.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Ojv_yS/simplejson-2.1.0/egg-dist-tmp-AypFWa
The required version of setuptools (>=0.6c11) is not available, and
can't be installed while this script is running. Please install
 a more recent version first, using 'easy_install -U setuptools'.

(Currently using setuptools 0.6c9 (/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python))
error: Setup script exited with 2

好的,我将更新 setuptools...

$ sudo easy_install -U setuptools
Searching for setuptools Reading
http://pypi.python.org/simple/setuptools/
Best match: setuptools 0.6c11
Processing setuptools-0.6c11-py2.6.egg
setuptools 0.6c11 is already the
active version in easy-install.pth
Installing easy_install script to
/usr/local/bin Installing
easy_install-2.6 script to
/usr/local/bin

Using
/Library/Python/2.6/site-packages/setuptools-0.6c11-py2.6.egg
Processing dependencies for setuptools
Finished processing dependencies for
setuptools

我不会去猜测,但这可能是由许多环境变化引起的,例如 Leopard -> Snow Leopard 升级、MacPorts 或 Fink 更新,或多个 Google App Engine 更新。

答案1

我按照以下网站上的说明操作,解决了我的问题:

http://pypi.python.org/pypi/setuptools

即下载适当的Python版本然后运行:

sh ./setuptools-0.6c11-py2.7.egg

答案2

默认情况下,OSX 使用 /usr/bin/easy_install 安装第三方软件包。此脚本被硬编码为使用比 pymongo 支持 python2.7 所需的版本更旧的 setuptools 版本。您可以像这样解决它:

$ easy_install -U setuptools
$ python -m easy_install pymongo

要升级,请执行以下操作:

$ python -m easy_install -U pymongo

相关内容