1

Despite the many stories that I've heard about people having problems installing numpy, scipy, and matplotlib on Mac OS X Lion, I've never had any problem until today. I recently updated my system and attempted to install the latest versions of NumPy and SciPy. The NumPy installation went fine and the test ran as expected, however the scipy installation seems to be incomplete. Every time I try to import scipy.stats I get the following error:

In [1]: import scipy.stats
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-b66176eb2d0a> in <module>()
----> 1 import scipy.stats

    /Library/Python/2.7/site-packages/scipy/stats/__init__.py in <module>()
    326 """
    327 
--> 328 from stats import *
    329 from distributions import *
    330 from rv import *

/Library/Python/2.7/site-packages/scipy/stats/stats.py in <module>()
    191 # Scipy imports.
    192 from numpy import array, asarray, dot, ma, zeros, sum
--> 193 import scipy.special as special
    194 import scipy.linalg as linalg
    195 import numpy as np

/Library/Python/2.7/site-packages/scipy/special/__init__.py in <module>()
    525 """
    526 
--> 527 from _ufuncs import *
    528 from _ufuncs_cxx import *
    529 

ImportError: dlopen(/Library/Python/2.7/site-packages/scipy/special/_ufuncs.so, 2): no     suitable image found.  Did find:
    /Library/Python/2.7/site-packages/scipy/special/_ufuncs.so: mach-o, but wrong   architecture

I am using the latest version of numpy and scipy off of github. For some reason it looks like the x86_64 version of the _ufuncs.so isn't being built. I've tried every compiler flag I can think of ARCHFLAGS="-arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64" FFLAGS="-m64 -ff2c"

and no mater what I do I get the same error. Any advice?

UPDATE So I think that I've found the problem, I will follow-up on the scipy distribution list:

Most of the libraries created when scipy builds are universal files meaning that they support both i386 and x86_64. The problem is that the files compiled with gfortran are compiled as i386 only.

> find . -name *.so | xargs -I {} lipo -info {}
Architectures in the fat file: ./build/lib.macosx-10.7-intel-2.7/scipy/cluster/_hierarchy_wrap.so are: i386 x86_64 
Architectures in the fat file: ./build/lib.macosx-10.7-intel-2.7/scipy/cluster/_vq.so are: i386 x86_64 
Non-fat file: ./build/lib.macosx-10.7-intel-2.7/scipy/fftpack/_fftpack.so is architecture: i386

I've checked my environment and I don't see anything suspicious. As specified on the SciPy Mac OS X page. I only export: CC=gcc-4.2 CXX=g++-4.2 FFLAGS=-ff2c

I just did install on another system and everything worked just fine.

aquil.abdullah
  • 3,059
  • 3
  • 21
  • 40
  • I noticed the response http://stackoverflow.com/questions/10046043/pip-easy-install-ignoring-archflags-in-scipy-installation but setting ARCHFLGS didn't work for me. – aquil.abdullah Jan 16 '13 at 01:09

3 Answers3

1

A similar question has already been answered here and I agree with it - installing in a virtualenv is the best way to go. OS X itself relies on specific versions of some Python libraries, making installing additional packages in the main Python interpreter a bit tricky at times (I had troubles with matplotlib for example).

Installing virtualenv is really quite simple as explained in this blog post and boiles down to installing virtualenv(wrapper)

pip install virtualenv virtualenvwrapper

sourcing it and creating a new environment you're gonna work in

source /usr/local/share/python/virtualenvwrapper.sh
mkvirtualenv system
workon system

You can now install anything you need from the Cheese shop. Add the source and workon commands to your .bashrc file so that this environment gets automatically selected.

Community
  • 1
  • 1
metakermit
  • 21,267
  • 15
  • 86
  • 95
  • Thanks for the help. I tried the install in a virtualenv, as you suggested, but it was still a no go. I think that I have some path issues with my compilers. As I am still not getting the Universal Binaries. – aquil.abdullah Jan 29 '13 at 21:22
  • http://stackoverflow.com/questions/12092306/how-to-install-scipy-with-pip-on-mac-mountain-lion-os-x-v10-8/18815061#18815061 My small guide. Works on OS X Mountain Lion 10.8.4 – andilabs Sep 15 '13 at 17:40
0

ScipySuperpack fixes all.

$ curl -o install_superpack.sh https://raw.github.com/fonnesbeck/ScipySuperpack/master/install_superpack.sh
$ sh install_superpack.sh
e9t
  • 15,534
  • 5
  • 23
  • 25
  • Thanks for the help, but sometimes I need to be on the bleeding edge of development, so ideally, I would like to be able to install any version of numpy, scipy, matplotlib, and pandas that I want. – aquil.abdullah Jan 29 '13 at 21:21
0

In the end I wound up removing all of my GNU compilers C, C++, and GFortran. And then reinstalling the 2.5.1 versions. I then set the environment variables:

CC=gcc-4.2
CXX=g++-4.2 
FFLAGS=-ff2c
ARCHFLAGS="-arch i386 -arch x86_64"

After that I built Scipy and voila! The universal binaries appeared:

[16:29:27] junebug:fftpack> lipo -info _fftpack.so 
Architectures in the fat file: _fftpack.so are: i386 x86_64

I am not sure what was wrong with the paths to my GNU compilers, but I think the problem may have been because I had multiple versions installed.

aquil.abdullah
  • 3,059
  • 3
  • 21
  • 40