开发者

How to install numpy and scipy on OSX?

开发者 https://www.devze.com 2023-02-01 06:17 出处:网络
I\'m new to Mac so please bear with me. I\'m using snow leopard 10.6.4 at the moment. I want to instal开发者_运维知识库l numpy and scipy, so I downloaded the python2.6,numpy and scipy dmg files from t

I'm new to Mac so please bear with me.

I'm using snow leopard 10.6.4 at the moment.

I want to instal开发者_运维知识库l numpy and scipy, so I downloaded the python2.6,numpy and scipy dmg files from their official site. However, I'm having problem import numpy:

Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper

Can anyone shed some light to this problem?


Sounds as though you might be trying to use a 32-bit library from a 64-bit Python. Looks like there's an unofficial 64-bit Numpy available for Snow Leopard.


EDIT: The Python 2.6 .dmg available here is indeed 32-bit. (Specifically, it's a universal binary containing both i386 and ppc versions). The same is true of the regular numpy and scipy .dmg releases available here. (How do I know? See below!) So if you use those releases together you should be fine.

But you're not fine - so my guess is you're not using the version of Python from the 2.6 .dmg you downloaded. If you're running an executable python script, e.g.:

$ ./my-script.py

then you could try specifying the Python you're using explicitly on the command line. Looks like the MacPython .dmg installs to /usr/local/bin/python, so try:

$ /usr/local/bin/python2.6 myscript.py

Any joy?


How I determined the architecture the contents of those .dmg files are built for...

  1. Mount the .dmg (i.e. double-click it to open a volume)
  2. Use gunzip and pax to unpack the package contents to a local directory, e.g.:

    $ mkdir tmp
    $ cd tmp
    $ gunzip -c /Volumes/Universal\ MacPython\ 2.6/MacPython.mpkg/Contents/Packages/PythonUnixTools-2.6.pkg/Contents/Archive.pax.gz | pax
    
  3. Use file to examine binary files in the package contents

    $ file Versions/2.6/bin/python
    Versions/2.6/bin/python: Mach-O universal binary with 2 architectures
    Versions/2.6/bin/python (for architecture ppc): Mach-O executable ppc
    Versions/2.6/bin/python (for architecture i386):    Mach-O executable i386
    


I had the same error message when I was trying my freshly-installed numpy and scipy in python2.7 on Mac OSX 10.6.8 . Later I found out that there were two .dmg for python2.7:

  • numpy-1.6.2-py2.7-python.org-macosx10.3.dmg
  • numpy-1.6.2-py2.7-python.org-macosx10.6.dmg

It was the package in 10.3.dmg giving me the error message about multiarray.so. After installing the one in 10.6.dmg, I got rid of this error message.


I had problems with numpy until I installed in a virtualenv, now I don't have any issues. I would definitely suggest trying that.


for snow leopard 64 bit i used the following man http://blog.hyperjeff.net/?p=160 just execute and you are good to go. Also look at the comments ( new AMD ...)

building numpy works all the time. but for scipy you need to provide the numpy config files. install gfortran .....


No need to use MacPorts or Fink.

Use the Python 2.6 installer and this Numpy installer. I think you need to have Numpy installed first, then install Scipy, and everything will work auto-magically. I remember that for a while, I needed to explicitly append the path to the site-packages directory at the top of my scripts for Python to know where to look.


The best way to manage packages on OS X is Fink (not MacPorts :) ). They have good Python, NumPy, and SciPy support.

Why use a package manager? because you will not only get NumPy and SciPy, but also many other programs that you will inevitably need, all with a single point of entry (basically the install command of the manager). This is much more convenient than having to hunt for specific compiled versions of the programs that you want to install.

Why Fink? because Fink is reputedly more stable than MacPorts, and has many more packages.


In case this is useful to someone, I also had problems installing numpy's binaries on OSX. The installer complained telling me that:

You cannot install numpy 1.5.1 on this volume. numpy requires System Python 2.6 to install.

Long story short: “System Python” means “python from python.org” and “2.6” means really 2.6, not 2.5 and not 2.7. So, go and find the installer for the version of python that numpy wants and then all is great.

On my first attempt I understood numpy's error as telling me that I had an outdated python, so I got the latest version (2.7 at the time), but numpy kept complaining all the same. Only after a careful reading of the message I understood that it really wanted 2.6 and not any other version. I trashed the first installation (found in /Library/Frameworks/Python.framework) and installed 2.6 after that. Finally numpy was happy to install and everything was fine.


I've spent countless hours browsing the web, trying to get various python packages working in OS X. In the end, I found the easiest solution was to either switch entirely to Ubuntu or run Ubuntu in Virtualbox from within OS X (all free of cost).

Using Ubuntu's package manager, apt-get, virtually any package you want will work out of the box after one simple install command. It was a huge rush the first time I got numpy, scipy, and matplotlib up and running in less than a minute.

$ sudo apt-get install python-numpy python-scipy python-matplotlib

I still get a mini-rush every time I do that. Not sure if there is a debian package for the module you want? Typically there is, and you can search for, say, python's lxml module with:

$ apt-cache search lxml | grep python
0

精彩评论

暂无评论...
验证码 换一张
取 消