问题
I am working on a OS X 10.7 with Python 2.7 from python.org and XCode 4.2.
- Following these instructions, I tried changing the
CC
,CXX
, andFFLAGS
variables and install withsudo pip install numpy
. However, the installation still looks forgcc-4.2
. - I tried
installing
gcc-4.2
through MacPorts but get thatError: gcc42 does not build on Snow Leopard or later.
When I install numpy from the precompiled binary on sourceforge, I get the following error:
import numpy
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/init.py", line 137, in
import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/init.py", line 4, in
from type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/init.py", line 5, in
import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper
Any help?
回答1:
If I recall correctly the precompiled binary on source forge is 32-bit. It took me ages to get Numpy, Scipy, and Matplotlib set up on my macbook, it's definitely much harder than it should be.
I believe that your best option is the Scipy superpack. Before using the superpack you need to update to Xcode 4.3.2
So I just installed python 2.7.2 from python.org, grabbed the superpack, and now have numpy working on my machine. After installing python 2.7.2, I did sudo pip uninstall numpy
, which didn't remove enough. So I cd'd into /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
and moved both the numpy directory and the numpy egg to "old" versions of themselves. Then I ran sh install_superpack.sh
and answered no to the "are you installing from a repository cloned to this machine(pretty important lol, hit yes without thinking the first time).
However, now I'm able to do this:
$ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> import matplotlib
With no problems :)
回答2:
SuperPack worked for me (thanks, @Nolen) on OS X 10.8 (Mountain Lion) w/ XCode 4.5.1 installed.
Numpy worked for me using pip install numpy
after step #1 below. But scipy would not install using pip. SuperPack fixed this.
The only thing I did differently was to use HomeBrew to install Python as step #1, rather than download it manually.
Install Python (separate from version that comes with OS X 10.8)
brew install python --framework --universal
pushd /System/Library/Frameworks/Python.framework/Versions
sudo rm Current
sudo ln -s /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/Current
popd
Install SuperPack:
curl -o install_superpack.sh https://raw.github.com/fonnesbeck/ScipySuperpack/master/install_superpack.sh
sh install_superpack.sh
- (type your admin password several times during the installation...)
来源:https://stackoverflow.com/questions/10057095/installing-numpy-lion-with-python-2-7