Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install NumPy for Python 3.2.3 on OS X 10.7.4

I have been trying for months to get numpy installed for Python 3 but despite copious amounts of Googling and even posting to the numpy mailing list I am still no closer to a solution.

I have managed to get it installed via MacPorts but unfortunately there doesn't appear to be a port of MatPlotLib for Python 3 which is the main reason I am trying to install numpy...so I am a bit stuck...

I keep getting the same error whilst trying to build from the setup.py file. I have included the terminal output below.

Thanks for any help you can offer,

Adam.

Here is the terminal output:

lipo: can't figure out the architecture type of: /var/folders/zj/7xymy_2n3s71ws30v3v_qnlw0000gn/T//ccbRr0Hj.out
failure.
removing: _configtest.c _configtest.o
Running from numpy source directory.Traceback (most recent call last):
  File "setup.py", line 214, in <module>
    setup_package()
  File "setup.py", line 207, in setup_package
    configuration=configuration )
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/core.py", line 186, in setup
    return old_setup(**new_attr)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 917, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build.py", line 37, in run
    old_build.run(self)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/command/build.py", line 126, in run
    self.run_command(cmd_name)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 152, in run
    self.build_sources()
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 169, in build_sources
    self.build_extension_sources(ext)
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 328, in build_extension_sources
    sources = self.generate_sources(sources, ext)
  File "/Users/adammcnicol/Downloads/numpy-1.6.2rc1/build/py3k/numpy/distutils/command/build_src.py", line 385, in generate_sources
    source = func(extension, build_dir)
  File "numpy/core/setup.py", line 410, in generate_config_h
    moredefs, ignored = cocache.check_types(config_cmd, ext, build_dir)
  File "numpy/core/setup.py", line 41, in check_types
    out = check_types(*a, **kw)
  File "numpy/core/setup.py", line 271, in check_types
    "Cannot compile 'Python.h'. Perhaps you need to "\
SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
like image 944
Adam McNicol Avatar asked May 11 '12 20:05

Adam McNicol


People also ask

How do I add NumPy to Python?

There are two ways to install numpy: Install the binary (pre-compiled) version using pip. Compile it from source code, and then install it.


2 Answers

Well, I finally managed to get NumPy to install. Not sure it is the best method but it seems to work!

First of all i needed to install distribute:

  1. curl http://python-distribute.org/distribute_setup.py | python3

Then I installed pip:

  1. curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3

After that I had to get pip on to my system path (again there are probably better ways):

  1. Open Terminal
  2. Type the following (single line):
    • sudo ln -s /Library/Frameworks/Python.framework/Versions/3.2/bin/pip /usr/local/bin

With distribute and pip installed I then installed Nose, which NumPy needs for testing or something:

  1. Again, in Terminal type the following:
    • pip install nose

Now I needed to make sure I had the latest version of Xcode:

  1. From the AppStore install the latest version of Xcode
  2. If you still have a /Developer folder then rename it Developer-old (not sure whether this will cause problems for me later or not)
  3. Open Terminal and create a symlink to the AppStore version of Xcode (single line):
    • sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer /Developer

With all of that out of the way time to install NumPy:

  1. Download the NumPy source from: http://sourceforge.net/projects/numpy/files/NumPy/1.6.2rc1/
  2. Unarchive the file
  3. Open Terminal again:
    • cd into the directory created by unarchiving the file e.g.
      • cd /Users/username/Downloads/numpy-1.6.2rc1
  4. Type into the Terminal the following to change the complier used to build NumPy:
    • export CC=clang
    • export CXX=clang
    • export FFLAGS=-ff2c
    • export LDSHARED='clang -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -g' (this is a single line)
    • python3 setup.py build (this may take a while)
    • python3 setup.py install

Okay, assuming there were no errors NumPy should be installed. Time to test it out:

  1. Open IDLE
  2. In the Python Shell type:
    • import numpy
    • numpy.test('full')
  3. This will test NumPy the final result I received with Python 3.2.3 was:
    • <nose.result.TextTestResult run=3192 errors=0 failures=1>

So the NumPy installation passes all except one test, which seems pretty good. I haven't had a chance to see if works properly yet as I am still struggling to get matplotlib installed...

Hope these instructions are useful to somebody!

Adam.

like image 94
Adam McNicol Avatar answered Oct 10 '22 01:10

Adam McNicol


I'm using Python 3.3 and OS X 10.7, and I installed numpy using a much easier method than above. I'm posting here in case it can help someone.

Follow these steps:

  • Download the zip file from numpy on github, and unpack it wherever you want.
  • Open a terminal and cd to the directory
  • enter the command python3 setup.py build --fcompiler=gnu95 (requires gfortran. Enter gfortran -v to see if you've got it, I've got version 4.6.2)
  • enter python3 setup.py install

That's all it took for me. Running numpy.test('full') gives me some errors, however: http://pastebin.com/5XF0qAe5

I don't know what kind of errors I'm going to experience yet.

like image 31
mrKelley Avatar answered Oct 09 '22 23:10

mrKelley