使用 easy_install 或 setup.py install 在 OSX 上安装 Python 模块 [英] Installing Python modules on OSX using easy_install or setup.py install
问题描述
我正在运行 Snow Leapord 10.6 并尝试安装以下 python 模块:
I am running Snow Leapord 10.6 and trying to install the following python modules:
- 麻木
- scipy
- matplotlib
我遇到了问题,因为 OSX 包含两个版本的 Python:
I am running into problems because OSX contains two version of Python:
- /图书馆/Python/
- /System/Library/Frameworks/Python.framework/
看来,当我执行以下命令时:
It appears that when I execute the following command:
sudo easy_install -U {module}
,模块正在安装到 site-packages 目录:
sudo easy_install -U {module}
, the modules are being installed to the site-packages directory here:
bash-3.2$ ls -al /Library/Python/2.6/site-packages/
total 688
drwxrwxr-x 12 root admin 408 Aug 24 23:26 .
drwxrwxr-x 3 root admin 102 Feb 11 2010 ..
-rw-rw-r-- 1 root admin 119 Feb 11 2010 README
-rw-r--r-- 1 root admin 267 Aug 24 19:03 easy-install.pth
drwxr-xr-x 5 root admin 170 Aug 24 10:42 nose-0.11.4-py2.6.egg
drwxr-xr-x 38 root admin 1292 Aug 24 15:35 numpy
-rw-r--r-- 1 root admin 1618 Aug 24 15:35 numpy-2.0.0.dev8661-py2.6.egg-info
drwxr-xr-x 16 root admin 544 Aug 24 19:07 numscons
drwxr-xr-x 4 root admin 136 Aug 24 19:03 numscons-0.10.1-py2.6.egg
-rw-r--r-- 1 root admin 265 Aug 24 19:07 numscons-0.12.0dev-py2.6.egg-info
-rw-r--r-- 1 root admin 333959 Aug 23 11:51 setuptools-0.6c11-py2.6.egg
-rw-r--r-- 1 root admin 30 Aug 23 11:51 setuptools.pth
但是,当我尝试安装 scipy 时,我看到以下错误:
But, when I try to install scipy, I see the following error:
config = setup_module.configuration(*args)
File "scipy/setup.py", line 20, in configuration
config.add_subpackage('special')
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/distutils/misc_util.py", line 851, in add_subpackage
caller_level = 2)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/distutils/misc_util.py", line 834, in get_subpackage
caller_level = caller_level + 1)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/distutils/misc_util.py", line 766, in _get_configuration_from_setup_py
('.py', 'U', 1))
File "scipy/special/setup.py", line 14, in <module>
(numpy.__version__, numpy.__file__))
ValueError: numpy >= 1.4 is required (detected 1.2.1 from /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/__init__.pyc)
所以它似乎在我的框架目录中寻找旧版本的 numpy.我使用 import 来查看找到哪个版本的 numpy python:
So it appears that it is looking for an older version of numpy in my frameworks directory. I used import to see which version of numpy python was finding:
python -c 'import numpy;print numpy.__version__'
1.2.1
果然,即使我有一个新版本,它也会在 frameworks 目录中查找:
And sure enough, it is looking in the frameworks directory even though I have a new version sitting in:
/Library/Python/2.6/site-packages/
我知道import首先搜索你的本地目录,然后进入PYTHONPATH,最后查看sys.path.所以我检查了这些,我现在没有设置 PYTHONPATH,这是我的 sys.path:
I know import searches your local directory first, and then goes into PYTHONPATH, and then finally looks at sys.path. So I checked these out and I do not have PYTHONPATH set right now, and here is my sys.path:
/Library/Python/2.6/site-packages/setuptools-0.6c11-py2.6.egg
/Library/Python/2.6/site-packages/nose-0.11.4-py2.6.egg
/Library/Python/2.6/site-packages/numscons-0.10.1-py2.6.egg
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload
/Library/Python/2.6/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode
如果我将 PYTHONPATH 更改为 /Library/Python/2.6/site-packages
然后检查 numpy 版本,我会得到正确的版本:
If I change PYTHONPATH to /Library/Python/2.6/site-packages
and then check the numpy revision I get the correct version:
bash-3.2$ python -c 'import numpy; print numpy.__version__'
2.0.0.dev8661
但是当我运行 sudo python setup.py build/install
时,scipy 找不到正确的 numpy,即使已经设置了 PYTHONPATH.
But when I run sudo python setup.py build/install
scipy cannot find the right numpy, even though PYTHONPATH has been set.
有人可以帮我吗?
发现这个链接似乎解决了我的问题,但我似乎无法让它工作:
Found this link that looks like it fixes my problem, but I cant seem to get it to work:
http://andreasjacobsen.com/2008/10/10/using-python-setuptools-on-the-mac/
推荐答案
我想出的解决方案如下.
The solution I came up with is the following.
1) 不要使用 OSX 预装的 Python 版本.Apple 显然已经对此进行了一些修改,但并非所有内容都已构建.因此,您需要安装 Python 的开发版本.现在 - 我建议安装 Python 2.7.这是一篇关于如何做到这一点的博客文章:
1) Do not use the version of Python that comes pre-installed with OSX. Apple has apparently made some modifications to this and not everything builds. So, you need to install a development version of Python. Right now - I would suggest installing Python 2.7. Here is a blog post about how to do it:
https://medium.com/cs-math/a3eb146ebfb5
2) 安装 Python 后,您需要为 Scipy/Numpy 安装安装 Fortran 库.使用自制软件来做到这一点(人们真的还在使用 MacPorts 吗???)
2) Once you have installed Python, you need to install the fortran libraries for the Scipy/Numpy installation. Use homebrew to do that (Do people really still use MacPorts ???)
3) 安装 home brew 后,安装 fortran
3) After you have home brew installed, install fortran
brew install gfortran
brew install gfortran
4) 现在您可以使用 pip 成功安装 scipy/numpy(警告 - 需要一段时间)
4) Now you can install scipy/numpy successfully with pip (Warning - it takes a while)
pip install -U numpypip install -U scipy
pip install -U numpy pip install -U scipy
完成
这篇关于使用 easy_install 或 setup.py install 在 OSX 上安装 Python 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!