Installing numpy Lion with Python 2.7?

南笙酒味 提交于 2020-01-01 04:57:46

问题


I am working on a OS X 10.7 with Python 2.7 from python.org and XCode 4.2.

  1. Following these instructions, I tried changing the CC, CXX, and FFLAGS variables and install with sudo pip install numpy. However, the installation still looks for gcc-4.2.
  2. I tried installing gcc-4.2 through MacPorts but get that Error: gcc42 does not build on Snow Leopard or later.
  3. 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.

  1. 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
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!