Install Python, NumPy, SciPy, and matplotlib on Mac OS X

Update: These instructions are over a year old, though they may still work for you. See the “Install Python” page for the most recent instructions.

A bit ago a friend and I both had fresh Mac OS X Lion installs so I helped him set up his computers with a scientific Python setup and did mine at the same time.

These instructions are for Lion but should work on Snow Leopard or Mountain Lion without much trouble. On Snow Leopard you won’t install Xcode via the App Store, you’ll have to download it from Apple.

After I’d helped my friend I found this blog post describing a procedure pretty much the same as below.

Update: If doing all the stuff below doesn’t seem like your cup of tea, it’s also possible to install Python, NumPy, SciPy, and matplotlib using double-click binary installers (resulting in a much less flexible installation), see this post to learn how.

Xcode

You will need Apple’s developer tools in order to compile Python and the other installs. On Lion you can install Xcode from the App Store, on Snow Leopard you’ll have to get an older Xcode from developer.apple.com.

I use the Xcode editor because I like its syntax highlighting, code completion, and organizer. However, I use hardly any of its features and unless you’re an iOS or Mac developer you probably won’t either. If you prefer another editor it’s possible to get only the libraries and compilers that you need with the Command Line Tools for Xcode. (You’ll need a free Apple ID.) (See also http://www.kennethreitz.com/xcode-gcc-and-homebrew.html.)

Homebrew

Homebrew is an excellent package manager for Mac OS X that can install a large number of packages. To install it simply launch a terminal and enter

ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

Homebrew installs things to /usr/local/ so you don’t need sudo permissions. To add Homebrew installed executables and Python scripts to your path you’ll want to add the following line to your .profile (or .bash_profile) file:

 export PATH=/usr/local/bin:/usr/local/share/python:$PATH

Normal executables go in /usr/local/bin/ and Python scripts installed by Homebrew go in /usr/local/share/python/.

See https://github.com/mxcl/homebrew/wiki/The-brew-command or type brew help or man brew for more info on Homebrew.

Install Python

Now that you’ve got Homebrew installing Python is simple:

brew install python

Homebrew will install a couple of packages required by Python and then Python itself. Don’t be surprised if this takes a couple minutes.

Important: You should close your terminal and open a fresh one right now so that it has the updated PATH from the previous section. Otherwise you run the risk of executing the wrong scripts during the rest of these instructions.

At this point you should be able to get a fresh terminal and type

which python

and see

/usr/local/bin/python

Homebrew is for installing system packages and tools; for managing Python add-ons we want pip. Luckily easy_install, another Python package manager is installed by Homebrew and we can use it to install pip:

easy_install pip

Install NumPy

Use pip to install NumPy:

pip install numpy

This should install NumPy 1.6.1 (as of Feb. 2012).

Install SciPy

We need gfortran to compile SciPy but it is not included with the other Xcode tools. Luckily, Homebrew can help us out again:

brew install gfortran

When that’s done it’s a cinch to install SciPy:

pip install scipy

This should install SciPy 0.10.

Install matplotlib

To install matplotlib we need to revisit Homebrew one more time:

brew install pkg-config

And the usual pip command:

pip install matplotlib

This should install matplotlib 1.2.0. If it doesn’t you can try installing from the matplotlib development repo:

pip install git+git://github.com/matplotlib/matplotlib.git

Congratulations! You should now have the basics of a scientific Python installation that’s easy to manage and upgrade using Homebrew and pip. Fire up Python and make sure things worked. The following should work in Python with no errors:

import numpy
import scipy
import matplotlib

Enjoy!

Install Python, NumPy, SciPy, and matplotlib on Mac OS X

76 thoughts on “Install Python, NumPy, SciPy, and matplotlib on Mac OS X

  1. Damian says:

    On latest lion with command line compiler tools installed, matplotlib installation fails:

    agg24/include/agg_renderer_outline_aa.h:1368:45: error: binding of reference to type ‘agg::line_profile_aa’ to a value of type ‘const agg::line_profile_aa’ drops qualifiers

    line_profile_aa& profile() { return *m_profile; }

    ^~~~~~~~~~
    1 error generated.
    error: command ‘/usr/bin/clang’ failed with exit status 1

    I tried replacing clang with llvm-gcc-4.2 (just overwrite temporarily clang) — same thing.

    Any ideas?

      1. Damian says:

        I tried both:
        pip install matplotlib

        that tried to install:
        matplotlib: 1.1.0
        python: 2.7.2 (default, Feb 25 2012, 09:03:36) [GCC 4.2.1
        Compatible Apple Clang 3.1
        (tags/Apple/clang-318.0.45)]
        platform: darwin
        and
        pip install git+git://github.com/matplotlib/matplotlib.git

        no difference in result.

      2. It looks like this is a known bug in matplotlib that should be fixed soon. In fact, it looks like it’s already been fixed in the development version. You might try reinstalling from github. You might also want to take a look at this thread from a few days ago.

        I’m not sure why your matplotlib is building with clang. I just did pip install matplotlib on my machine and it compiles with llvm-gcc.

      3. Damian says:

        (looks like deeper replies are not allowed)

        The latest github state passes: Yay – thank you!

      1. Sylvester says:

        Hi Jiffyclub,

        I have a problem running homebrew command in my mac terminal. I get the following error:
        ruby -e “$(curl -fsSkL raw.github.com/mxcl/homebrew/go)”
        File “”, line 1
        ruby -e “$(curl -fsSkL raw.github.com/mxcl/homebrew/go)”
        ^
        SyntaxError: invalid syntax

        Please help if you can

        Thanks!

  2. Justin R says:

    Matt – thanks for writing this. I’d been meaning to get started with Python for months, and this easy tutorial gave me motivation to do it.

    Couple things:
    (1) I had trouble with the curl command at the very beginning for homebrew; with help from an officemate, we fixed that by copying the script to a .rb file and running it with /usr/bin/ruby.

    (2) Everything appeared to install fine, and I did a rehash, but after starting python and trying to import the new packages I get:
    ImportError: No module named numpy

    Thoughts on that?

    1. One thing is to make sure you’ve started the right Python. If you type which python in a terminal do you get /usr/local/bin/python? If instead you get /usr/bin/python then you want to set your PATH as described in the Homebrew section above.

      If you’ve got the right Python but still no NumPy check this directory, that’s where it should be installed: /usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/. If you don’t see it there then it was probably installed somewhere else for some reason. You’ll again want to check your PATH and make sure you’re using the right easy_install and pip. which pip should give /usr/local/share/python/pip. If you get a different pip you’ll again want to make sure you’ve got your PATH set correctly and start again from the easy_install pip step.

      1. Nick says:

        I installed numpy but from there onwards everything is bad! When I do which pip I get “/usr/local/bin/pip”. When I go into /usr/local/Cellar/python/2.7.3 there isn’t even a lib file! Any ideas? This is my .bash_profile:

        # Setting PATH for Python 2.7
        # The orginal version is saved in .bash_profile.pysave
        PATH=”/usr/local/bin/python:${PATH}”
        export PATH=/usr/local/bin:/usr/local/share/python:$PATH

        Sorry to be a hassle! I really need to get this working asap. Thanks, Nick

      2. Lennard says:

        I have the same problem as Nick,
        pip is installed in /usr/local/bin/pip, but links to pip inside the Cellar, so that seems OK.
        problems start when installing scipy, starting with:

        umfpack_info:
        libraries umfpack not found in /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib
        libraries umfpack not found in /usr/local/lib
        libraries umfpack not found in /usr/lib
        /usr/local/lib/python2.7/site-packages/numpy/distutils/system_info.py:470: UserWarning:
        UMFPACK sparse solver (http://www.cise.ufl.edu/research/sparse/umfpack/)
        not found. Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [umfpack]) or by setting
        the UMFPACK environment variable.
        warnings.warn(self.notfounderror.__doc__)
        NOT AVAILABLE

        and much more packages that can’t be found after that

        The /usr/local/Cellar/python/2.7.3/Frameworks/Python.framwork/Versions/2.7/lib folder doesn’t exist, as nick stated. Has something changed in the current version? I don’t get it…

      3. Lennard says:

        Ahhh sorry for not doing enough googling:
        fixed it by manually compiling numpy and then installing with:
        python setup.py install –prefix=/usr/local
        cheers,
        Lennard

      4. Glad you got it working! Homebrew installs pip to /usr/local/share/python so it’s odd you have one in /usr/local/bin. That may be part of the issue and manually installing NumPy works around it.

      5. Lennard says:

        as far as I know numpy now installs with the python from homebrew, I made sure I deleted all other versions of python. Also /usr/local/bin/python links to the Cellar. In /usr/local/lib/python2.7/ there are libraries needed for compiling scipy for instance.
        Although scipy now compiles, scipy.test() results in 50+ errors. Apparently it’s a known bug, something to do with gfortran and the like with macosx, didn’t find anything on how to solve it yet.

  3. Damian says:

    If you run an matplotlib example, you may find the script though not showing any errors, just hanges and does not plotting anything.

    Edit ~/.matplotlib/matplotlibrc and add:

    backend: MacOSX

    Worked for me.

  4. Thanks for the great post.

    It could be nice to advice to run `brew doctor` and remove old dependencies for systems that are not clean. Otherwise installing `pkg-config` and `gfortran` can be useless (because shadowed by old libraries).

  5. Hey Matt!

    I really appreciate the instructions you’ve been posting on here. It was super-convenient to use the double-click install on my work machine, however I wish that python had tab completion (presumably from readline). Does this “CIY” version compile with readline, or support tab completion some other way?

    Thanks!

      1. Yeah, after seeing the HTML Notebook on your site that’s my goal–I have some class exercises in IDL I’d like to rewrite in python. So you totally answered my question, but I asked something different that what I intended. =) I’m actually looking for the unix-like command line editing that I believe readline provides. I’m wondering if that just works with the CIY method.

        I also have just learned that, apparently, the libedit library on OS X can provide this, and it may be possible to turn that on post-install with just a configuration file.

        Thanks, I appreciate you sharing your expertise! The last time I installed a computer with all my analysis software was more than a few years ago, and a lot has changed since then!

      2. Homebrew does compile Python against readline so all of the Control-letter commands work in the interactive interpreter. However, I’d recommend the IPython notebook regardless.

  6. Azalee says:

    Hi Matt,

    This is awesome. Thanks so much. These were the changes to your directions above that I had to make, all very painless:
    Homebrew url changed again. I used: /usr/bin/ruby -e “$(/usr/bin/curl -fsSkL raw.github.com/mxcl/homebrew/go)”

    I didn’t have to do: brew install pkg-config, apparently pkg-config was already installed.

    I’m adding some comments to your Mountain Lion Post as well, I ran into more problems than you did.

    -Azalee

  7. AAA says:

    I follow your post to install python and numpy.
    I successfully installed python on my mac book (Mac OS X Lion 10.7.5) but after running the command pip install numpy I get this error:

    Downloading/unpacking numpy
    Running setup.py egg_info for package numpy
    Running from numpy source directory.non-existing path in ‘/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils’: ‘site.cfg’
    F2PY Version 2
    blas_opt_info:
    FOUND:
    extra_link_args = [‘-Wl,-framework’, ‘-Wl,Accelerate’]
    define_macros = [(‘NO_ATLAS_INFO’, 3)]
    extra_compile_args = [‘-msse3’, ‘-I/System/Library/Frameworks/vecLib.framework/Headers’]

    lapack_opt_info:
    FOUND:
    extra_link_args = [‘-Wl,-framework’, ‘-Wl,Accelerate’]
    define_macros = [(‘NO_ATLAS_INFO’, 3)]
    extra_compile_args = [‘-msse3’]

    build_src
    building py_modules sources
    building library “npymath” sources
    customize NAGFCompiler
    Could not locate executable f95
    customize AbsoftFCompiler
    Could not locate executable f90
    Could not locate executable f77
    customize IBMFCompiler
    Could not locate executable xlf90
    Could not locate executable xlf
    customize IntelFCompiler
    Could not locate executable ifort
    Could not locate executable ifc
    customize GnuFCompiler
    Could not locate executable g77
    customize Gnu95FCompiler
    Could not locate executable gfortran
    customize G95FCompiler
    Could not locate executable g95
    customize PGroupFCompiler
    Could not locate executable pgfortran
    don’t know how to compile Fortran code on platform ‘posix’
    C compiler: xcrun clang -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -O3 -Wall -Wstrict-prototypes

    compile options: ‘-I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/src/private -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/src -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/src/npymath -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/src/multiarray -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/src/umath -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/include -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c’
    xcrun: _configtest.c
    xcrun clang _configtest.o -o _configtest
    ld: library not found for -lcrt1.10.6.o
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    ld: library not found for -lcrt1.10.6.o
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    failure.
    removing: _configtest.c _configtest.o
    Traceback (most recent call last):
    File “”, line 16, in
    File “/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/setup.py”, line 214, in
    setup_package()
    File “/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/setup.py”, line 207, in setup_package
    configuration=configuration )
    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/core.py”, line 186, in setup
    return old_setup(**new_attr)
    File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py”, line 152, in setup
    dist.run_commands()
    File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py”, line 953, in run_commands
    self.run_command(cmd)
    File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py”, line 972, in run_command
    cmd_obj.run()
    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/command/egg_info.py”, line 8, in run
    self.run_command(“build_src”)
    File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py”, line 326, in run_command
    self.distribution.run_command(command)
    File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py”, line 972, in run_command
    cmd_obj.run()
    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/command/build_src.py”, line 152, in run
    self.build_sources()
    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/command/build_src.py”, line 163, in build_sources
    self.build_library_sources(*libname_info)
    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/command/build_src.py”, line 298, in build_library_sources
    sources = self.generate_sources(sources, (lib_name, build_info))
    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/command/build_src.py”, line 385, in generate_sources
    source = func(extension, build_dir)
    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/setup.py”, line 696, in get_mathlib_info
    raise RuntimeError(“Broken toolchain: cannot link a simple C program”)
    RuntimeError: Broken toolchain: cannot link a simple C program
    Complete output from command python setup.py egg_info:
    Running from numpy source directory.non-existing path in ‘/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils’: ‘site.cfg’

    F2PY Version 2

    blas_opt_info:

    FOUND:

    extra_link_args = [‘-Wl,-framework’, ‘-Wl,Accelerate’]

    define_macros = [(‘NO_ATLAS_INFO’, 3)]

    extra_compile_args = [‘-msse3’, ‘-I/System/Library/Frameworks/vecLib.framework/Headers’]

    lapack_opt_info:

    FOUND:

    extra_link_args = [‘-Wl,-framework’, ‘-Wl,Accelerate’]

    define_macros = [(‘NO_ATLAS_INFO’, 3)]

    extra_compile_args = [‘-msse3’]

    running egg_info

    running build_src

    build_src

    building py_modules sources

    building library “npymath” sources

    customize NAGFCompiler

    Could not locate executable f95

    customize AbsoftFCompiler

    Could not locate executable f90

    Could not locate executable f77

    customize IBMFCompiler

    Could not locate executable xlf90

    Could not locate executable xlf

    customize IntelFCompiler

    Could not locate executable ifort

    Could not locate executable ifc

    customize GnuFCompiler

    Could not locate executable g77

    customize Gnu95FCompiler

    Could not locate executable gfortran

    customize G95FCompiler

    Could not locate executable g95

    customize PGroupFCompiler

    Could not locate executable pgfortran

    don’t know how to compile Fortran code on platform ‘posix’

    C compiler: xcrun clang -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -O3 -Wall -Wstrict-prototypes

    compile options: ‘-I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/src/private -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/src -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/src/npymath -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/src/multiarray -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/src/umath -I/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/include -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c’

    xcrun: _configtest.c

    xcrun clang _configtest.o -o _configtest

    ld: library not found for -lcrt1.10.6.o

    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    ld: library not found for -lcrt1.10.6.o

    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    failure.

    removing: _configtest.c _configtest.o

    Traceback (most recent call last):

    File “”, line 16, in

    File “/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/setup.py”, line 214, in

    setup_package()

    File “/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/setup.py”, line 207, in setup_package

    configuration=configuration )

    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/core.py”, line 186, in setup

    return old_setup(**new_attr)

    File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py”, line 152, in setup

    dist.run_commands()

    File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py”, line 953, in run_commands

    self.run_command(cmd)

    File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py”, line 972, in run_command

    cmd_obj.run()

    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/command/egg_info.py”, line 8, in run

    self.run_command(“build_src”)

    File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py”, line 326, in run_command

    self.distribution.run_command(command)

    File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py”, line 972, in run_command

    cmd_obj.run()

    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/command/build_src.py”, line 152, in run

    self.build_sources()

    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/command/build_src.py”, line 163, in build_sources

    self.build_library_sources(*libname_info)

    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/command/build_src.py”, line 298, in build_library_sources

    sources = self.generate_sources(sources, (lib_name, build_info))

    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/distutils/command/build_src.py”, line 385, in generate_sources

    source = func(extension, build_dir)

    File “/private/var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy/numpy/core/setup.py”, line 696, in get_mathlib_info

    raise RuntimeError(“Broken toolchain: cannot link a simple C program”)

    RuntimeError: Broken toolchain: cannot link a simple C program

    —————————————-
    Command python setup.py egg_info failed with error code 1 in /var/folders/k9/3cg3j23s0slbwbym9fkshj9r0000gn/T/pip-build/numpy

    Can you please help me with this.
    Thanks

  8. Thanks a bunch for this concise and correct guide to getting Python up and running on Mac. Was having a ‘mare with a clean install and following this sorted it right out!

  9. Hi all … I have some tradition in building numpy/scipy (with optimized libs like suite-sparse) on the Mac (and Linux earlier). When I learned about Homebrew, I started to join the project to improve Python support and make the “scipy-superpack” kind of obsolete.

    We know `pip` is bad at pulling dependencies. Therefore, I’d like to introduce my own Homebrew “tap” (=easy-to-add repo of additional formulae) at https://github.com/samueljohn/homebrew-python.
    I can support you there (just open an issue) when you get into trouble (instead of spamming in this comments thread :-)

    You can then:
    `brew tap samueljohn/python`
    and `brew install numpy scipy matplotlib pillow` (may tell you that you need to `pip install nose` because homebrew does not aim to include pure python modules that build just fine with pip). If you love bleeding edge, you may want to try `brew install numpy –HEAD`.

    I’d love to get your feedback and suggestions. This is my little contribution to the Python community. Hope my homebrew scripts may save you the one or the other minute in getting a decent scientific Python setup on the Mac.

  10. Inno says:

    hello,
    thanks for the guide but i have prolem installing matplotlib.
    i followed your instructions but got stocked at “pip install matplotlib”..here is the error message.
    using the first option(pip install matplotlib), i get:
    pymods [‘pylab’]
    packages [‘matplotlib’, ‘matplotlib.backends’, ‘matplotlib.backends.qt4_editor’, ‘matplotlib.projections’, ‘matplotlib.testing’, ‘matplotlib.testing.jpl_units’, ‘matplotlib.tests’, ‘mpl_toolkits’, ‘mpl_toolkits.mplot3d’, ‘mpl_toolkits.axes_grid’, ‘mpl_toolkits.axes_grid1’, ‘mpl_toolkits.axisartist’, ‘matplotlib.sphinxext’, ‘matplotlib.tri’, ‘matplotlib.delaunay’, ‘pytz’, ‘dateutil’, ‘dateutil.zoneinfo’]

    warning: no files found matching ‘KNOWN_BUGS’
    warning: no files found matching ‘INTERACTIVE’
    warning: no files found matching ‘make.osx’
    warning: no files found matching ‘MANIFEST’
    warning: no files found matching ‘__init__.py’
    warning: no files found matching ‘examples/data/*’
    warning: no files found matching ‘lib/mpl_toolkits’
    warning: no files found matching ‘lib/matplotlib/mpl-data/matplotlib.conf’
    warning: no files found matching ‘lib/matplotlib/mpl-data/matplotlib.conf.template’
    warning: manifest_maker: MANIFEST.in, line 16: ‘recursive-include’ expects …

    warning: no files found matching ‘LICENSE*’ under directory ‘license’
    Installing collected packages: matplotlib
    Running setup.py install for matplotlib
    basedirlist is: [‘/usr/local/’, ‘/usr’, ‘/usr/X11’, ‘/opt/local’]

    second options(downloading for the website), i get:
    freetype2: found, but unknown version (no pkg-config)

    cc -fno-strict-aliasing -fno-common -dynamic -I/usr/local/include -I/usr/local/opt/sqlite/include -DNDEBUG -g -fwrapv -O3 -Wall -DPY_ARRAY_UNIQUE_SYMBOL=MPL_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -I/usr/local/include -I/usr/include -I/usr/X11/include -I/opt/local/include -I/usr/local/include -I/usr/include -I. -I/usr/local/lib/python2.7/site-packages/numpy/core/include -I. -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/_png.cpp -o build/temp.macosx-10.8-x86_64-2.7/src/_png.o

    src/_png.cpp:23:13: fatal error: ‘png.h’ file not found

    # include

    ^

    1 error generated.

    error: command ‘cc’ failed with exit status 1

    —————————————-
    Command /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c “import setuptools;__file__=’/private/var/folders/7q/0s9d01f50gn_j01xd2_709jh0000gn/T/pip-build-Eberechi/matplotlib/setup.py’;exec(compile(open(__file__).read().replace(‘\r\n’, ‘\n’), __file__, ‘exec’))” install –record /var/folders/7q/0s9d01f50gn_j01xd2_709jh0000gn/T/pip-C70ej3-record/install-record.txt –single-version-externally-managed failed with error code 1 in /private/var/folders/7q/0s9d01f50gn_j01xd2_709jh0000gn/T/pip-build-Eberechi/matplotlib
    Storing complete log in /Users/Eberechi/.pip/pip.log

    thank you,hope you can help me. thank you

    regards

    1. I’d stick with “pip install matplotlib”, I just tried it and it worked for me installing version 1.2.1. I got very similar output to you but at the end it said “Successfully installed matplotlib”.

      1. decaff Smith says:

        Thank you for the feed back. Is there a particular version of Anaconda that you would recommend for osx 10.6.8?

  11. FYI: I got this error installing matplotlib:
    fatal error: ‘ft2build.h’ file not found

    Fixed it by installing freetype and libpng via homebrew.

  12. Thanks for the thread. I followed the steps exactly however when I type which python it comes out: usr/bin/python instead of the one brew does. How to change it?
    First few lines in my .bash_profile:
    PATH=”/usr/local/bin:$PATH”
    export PATH
    export PATH=/usr/local/bin:$PATH
    export PATH=/usr/local/share/python:$PATH
    test -r /sw/bin/init.sh && . /sw/bin/init.sh
    —————————
    Because I firstly ignore it and did the follow-ups, then I can’t even install pip…
    error: can’t create or remove files in install directory

    The following error occurred while trying to add or remove files in the
    installation directory:

    [Errno 13] Permission denied: ‘/Library/Python/2.7/site-packages/test-easy-install-21675.write-test’

    The installation directory you specified (via –install-dir, –prefix, or
    the distutils default setting) was:

    /Library/Python/2.7/site-packages/
    —————————
    Then I went back to usr/local/bin I saw brew, ipython, gfortran, pkg-configure etc just everything should show up except python! Could you give me some suggestions?

    I’m very much appreciated!

      1. Yes I did install fink before. But I’m not sure how to revise the bash profile without causing problems in my other programs… What I did was just following texts online… Dunno which line is redundant which is not….

      2. My suspicion is that you are having trouble because the Homebrew installed stuff is not coming up first on your PATH. Fink is for sure messing with your PATH after you’ve added the Homebrew dirs. What do you see with type pip?

  13. Hi I found this article really useful (god what a pain scipy is to install on the mac). BUT it didn’t quite work for OSX 10.8.5. If, like me, you get the error:

    KeyError: ‘FARCHFLAGS’

    when trying to install scipy then you need to add the line :
    export FARCHFLAGS=”-arch x86_64″

    before you run
    pip install scipy

    Hope this helps

  14. Dave says:

    Nice instructions. Worked for me on Mavericks (10.9 OS X). I did, however, have to brew install freetype to get rid of the fatal error: ‘png.h’ file not found.

  15. Alex says:

    I am new to this whole python thing.

    Trying to follow your instructions to install everything on Mac OS X 10.6.8. I have followed all instructions up to installing NumPy. When I “which python” I get “/usr/local/bin/python”, when i “which pip” I get “/usr/local/bin/pip”, I dont know if this is a problem.

    I am now trying to install NumPy, using “pip install numpy” I get

    “Requirement already satisfied (use –upgrade to upgrade): numpy in /usr/local/lib/python2.7/site-packages/numpy-1.8.1-py2.7-macosx-10.6-x86_64.egg
    Cleaning up…”

    but when I try to import numpy in python (through the terminal) i get
    “Traceback (most recent call last):
    File “”, line 1, in
    ImportError: No module named numpy”

    Can you help me out, if possible? Cheers

      1. The current version of Anaconda is 10.7+, but you can download older versions of the installer. I don’t know which one will work on 10.6.

      2. aashbourne says:

        Thanks for all the help. I run 10.6.8, but I just downloaded from the link on the site and everything seems to work out fine.

  16. Shaune says:

    I am trying to install python and I have been able to do everything but scipy. I get the following:
    pip install scipy
    Downloading/unpacking scipy
    Cleaning up…
    Exception:
    Traceback (most recent call last):
    File “/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py”, line 122, in main
    status = self.run(options, args)
    File “/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py”, line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
    File “/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py”, line 1197, in prepare_files
    do_download,
    File “/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py”, line 1375, in unpack_url
    self.session,
    File “/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/download.py”, line 546, in unpack_http_url
    resp = session.get(target_url, stream=True)
    File “/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/requests/sessions.py”, line 468, in get
    return self.request(‘GET’, url, **kwargs)
    File “/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/download.py”, line 237, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
    File “/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/requests/sessions.py”, line 456, in request
    resp = self.send(prep, **send_kwargs)
    File “/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/requests/sessions.py”, line 559, in send
    r = adapter.send(request, **kwargs)
    File “/usr/local/Cellar/python/2.7.7_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/requests/adapters.py”, line 384, in send
    raise Timeout(e, request=request)
    Timeout: HTTPSConnectionPool(host=’pypi.python.org’, port=443): Read timed out.

    Storing debug log for failure in /Users/shaune/.pip/pip.log

    HELP!!!!!!

  17. decaff Smith says:

    Running into errors while trying to install scipy:

    Obtaining scipy from git+https://github.com/scipy/scipy#egg=scipy-dev
    Exception:
    Traceback (most recent call last):
    File “/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/pip/basecommand.py”, line 232, in main
    status = self.run(options, args)
    File “/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/pip/commands/install.py”, line 339, in run
    requirement_set.prepare_files(finder)
    File “/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/pip/req/req_set.py”, line 270, in prepare_files
    logger.info(‘Obtaining %s’, req_to_install)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 1021, in info
    self._log(INFO, msg, args, **kwargs)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 1129, in _log
    self.handle(record)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 1139, in handle
    self.callHandlers(record)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 1176, in callHandlers
    hdlr.handle(record)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 658, in handle
    rv = self.filter(record)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 558, in filter
    for f in self.filters:
    AttributeError: BetterRotatingFileHandler instance has no attribute ‘filters’

    Traceback (most recent call last):
    File “/usr/local/bin/pip”, line 8, in
    load_entry_point(‘pip==6.0.8’, ‘console_scripts’, ‘pip’)()
    File “/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/pip/__init__.py”, line 217, in main
    return command.main(cmd_args)
    File “/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/pip/basecommand.py”, line 258, in main
    logger.critical(‘Exception:\n%s’, format_exc())
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 1065, in critical
    self._log(CRITICAL, msg, args, **kwargs)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 1129, in _log
    self.handle(record)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 1139, in handle
    self.callHandlers(record)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 1176, in callHandlers
    hdlr.handle(record)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 658, in handle
    rv = self.filter(record)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py”, line 558, in filter
    for f in self.filters:

    1. This appears to be a bug in Python 2.6.1, you need to use a different version of Python. I strongly suggest installing Anaconda unless for some reason you need the bleeding edge version of SciPy.

  18. Rabh says:

    For me, it is still complaining about 2.6. I tried to install Anaconda as well (python 3.4 https://www.continuum.io/downloads). How can I fix this? Please help

    $python –version
    Python 2.7.10

    $pip install –upgrade pip
    You are using pip version 6.0.8, however version 7.1.2 is available.
    You should consider upgrading via the ‘pip install –upgrade pip’ command.
    Collecting pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-7.1.2-py2.py3-none-any.whl#md5=5ff9fec0be479e4e36df467556deed4d
    Using cached pip-7.1.2-py2.py3-none-any.whl
    Installing collected packages: pip
    Found existing installation: pip 6.0.8
    Uninstalling pip-6.0.8:
    Exception:
    Traceback (most recent call last):
    File “/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/pip/basecommand.py”, line 232, in main
    status = self.run(options, args)
    File “/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/pip/commands/install.py”, line 347, in run
    root=options.root_path,
    File “/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/pip/req/req_set.py”, line 543, in install
    requirement.uninstall(auto_confirm=True)
    File “/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/pip/req/req_install.py”, line 667, in uninstall
    paths_to_remove.remove(auto_confirm)
    File “/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/pip/req/req_uninstall.py”, line 126, in remove
    renames(path, new_path)
    File “/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/pip/utils/__init__.py”, line 316, in renames
    shutil.move(old, new)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/shutil.py”, line 258, in move
    rmtree(src)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/shutil.py”, line 212, in rmtree
    rmtree(fullname, ignore_errors, onerror)
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/shutil.py”, line 217, in rmtree
    onerror(os.remove, fullname, sys.exc_info())
    File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/shutil.py”, line 215, in rmtree
    os.remove(fullname)
    OSError: [Errno 13] Permission denied: ‘/Library/Python/2.6/site-packages/pip-6.0.8-py2.6.egg/EGG-INFO/dependency_links.txt’

  19. sunny says:

    when i type easy_install pip i am getting a message like this
    -bash: /usr/local/bin/easy_install: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory.. what to do??

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.