[Pythonmac-SIG] Building numpy/scipy for python3 on MacOS Lion
Ned Deily
nad at acm.org
Thu Mar 22 01:41:54 CET 2012
In article <1332374918.1428.YahooMailNeo at web29504.mail.ird.yahoo.com>,
Eddy Barratt <eddybarratt1 at yahoo.co.uk> wrote:
> I can't get Numpy or Scipy to work with Python3 on Mac OSX Lion.
>
>
> I have used pip successfully to install numpy, scipy and matplotlib, and they
> work well with Python2.7, but in Python3 typing 'import numpy' brings up 'No
> module named numpy'. I've tried downloading the source code directly and then
> running 'python3 setup.py build', but I get various error warnings, some in
> red that have to do with fortran (e.g. 'Could not locate executable f95'). In
> the end I get the following message:
>
> 2 warnings generated.
> gcc-4.2 -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot
> /Developer/SDKs/MacOSX10.6.sdk -isysroot /Developer/SDKs/MacOSX10.6.sdk -g
> build/temp.macosx-10.6-intel-3.2/numpy/core/src/dummymodule.o
> -Lbuild/temp.macosx-10.6-intel-3.2 -o
> build/lib.macosx-10.6-intel-3.2/numpy/core/_dummy.so
> sh: gcc-4.2: command not found
> sh: gcc-4.2: command not found
> error: Command "gcc-4.2 -bundle -undefined dynamic_lookup -arch i386 -arch
> x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -isysroot
> /Developer/SDKs/MacOSX10.6.sdk -g
> build/temp.macosx-10.6-intel-3.2/numpy/core/src/dummymodule.o
> -Lbuild/temp.macosx-10.6-intel-3.2 -o
> build/lib.macosx-10.6-intel-3.2/numpy/core/_dummy.so" failed with exit status
> 127
>
>
> The Scipy website (http://www.scipy.org/Installing_SciPy/Mac_OS_X) suggests
> that there may be issues with the c compiler, but the same problems didn't
> arise using pip to install for python2.7. I have followed the instructions on
> the website regarding changing the compiler but this has not made any
> difference.
Chances are you are using a Python 3.2.x installer from python.org.
Those Pythons are built using gcc-4.2 from Xcode 3 on OS X 10.6. When
installing 3rd-party packages with C extension modules, Python's
Distutils will attempt to use the same compiler and compiler options
Unfortunately, in the latest versions of Xcode 4, Apple has removed
gcc-4.2. That's why you see the gcc-4.2 not found. The instructions
given at the SciPy website for working around the problem by using clang
appear to be missing at least one important step. Besides overriding
the CC environment variable, you also will need to override LDSHARED
(untested with SciPy!):
$ export CC=clang
$ export LDSHARED='clang -bundle -undefined dynamic_lookup \
-arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -g'
In the upcoming 3.2.3 maintenance release, Distutils will do the
equivalent automatically if gcc-4.2 is called for but not present on the
machine.
Chances are that you are using the Apple-supplied Python 2.7 in 10.7,
rather than a python.org version which should exhibit the same behavior
as what you see with Python 3. The Apple system Python 2.7 is built
with llvm-gcc, not gcc-4.2, so you wouldn't see this problem with it.
However, as the SciPy page notes, there have been test failures noted
when using llvm-gcc to build Python and it is recommend to not use it as
it is not being actively maintained and is intended as a stepping stone
to use of clang throughout OS X.
Note that, starting with Xcode 4.3, Apple has made yet another major
change: moving the contents of the former /Developer directory to inside
the Xcode.app bundle itself. If you start with Xcode 4.3 or follow the
installation step of allowing Xcode to remove the old /Developer
directory, Distutils-initiated compiles will fail because they can't
find the SDK with OS X header files. The workaround for that is to
create a symlink from the new location to the old:
$ sudo ln -s
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Deve
loper /Developer
--
Ned Deily,
nad at acm.org
More information about the Pythonmac-SIG
mailing list