Install Python, NumPy, SciPy, and matplotlib on Mac OS X – Double Click

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

I’ve already written a post about installing Python, NumPy, SciPy, and matplotlib on Lion, but it involves a lot of working at the command line, modifying your .bash_profile and dealing with compiler problems. That’s what I’ll call the compile-it-yourself (CIY) method. What I’ll describe below I’ll call the “double click” method.

I personally use the CIY method because it allows me to very easily control what’s installed. With Homebrew and pip I can uninstall and upgrade different things at will, or choose to install bleeding-edge versions. But it’s more hassle than everyone wants and there’s now an easier way using double-click installers.

Until recently the CIY was the only way to get everything working on Lion but now the developers of NumPy, SciPy, and matplotlib have all caught up and it’s possible to just download and double-click on a few DMG files to get a basic scientific Python installation working. Once you get to know Python, though, you will undoubtedly want to install some other packages and when that time comes I suggest you use pip.

Note: I’ve provided the names of the most current packages as of March 1, 2012. By the time you do this the versions may have been updated so the most recent versions may not exactly match the names below. Make sure you get the most recent version that is explicitly for Mac OS 10.6-10.7+.

Install Python

Go to the Python download page and download the package called Python 2.7.2 Mac OS X 64-bit/32-bit x86-64/i386 Installer. Double-click the downloaded .dmg file to install Python.

Install NumPy

Go to the NumPy download page and download the package called numpy-1.6.1-py2.7-python.org-macosx10.6.dmg. Install as usual.

Install SciPy

Go to the SciPy download page and download the package called scipy-0.10.1-py2.7-python.org-macosx10.6.dmg. Install as usual.

Install matplotlib

Go to the matplotlib download page and download the package called matplotlib-1.2.0-py2.7-python.org-macosx10.6.dmg. Install as usual.

Congratulations, that should do it! If you ever want to upgrade one of these in the future revisit the appropriate download page and get the latest .dmg file. Fire up Python at a terminal 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 – Double Click

25 thoughts on “Install Python, NumPy, SciPy, and matplotlib on Mac OS X – Double Click

  1. Erisa says:

    Hey, I am using a tool (it is a python script not written by me) which requires all the libraries mentioned in this post to be installed in order to generate graphs.
    I have a Mac 10.6 (snow leopard), and successfully followed your instructions. Now I have installed Python 2.7, NumPy 1.6.2, SciPy 0.11.0b1, and Matplotlib 1.1.0
    However, I didn’t succeed to run the script.
    First error I got was that pylab couldn’t be imported, though from doing “import pylab” from a python shell I could see it was installed.

    So I just added the following line to my .profile file:

    export PYTHONPATH=”/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH”

    Now I am getting this error:

    Traceback (most recent call last):
    File “/usr/local/bin/tsplot”, line 45, in
    from pylab import *
    File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pylab.py”, line 1, in
    from matplotlib.pylab import *
    File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.py”, line 133, in
    from matplotlib.rcsetup import (defaultParams,
    File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/rcsetup.py”, line 19, in
    from matplotlib.colors import is_color_like
    File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/colors.py”, line 52, in
    import numpy as np
    File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py”, line 137, in
    import add_newdocs
    File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py”, line 9, in
    from numpy.lib import add_newdoc
    File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/__init__.py”, line 4, in
    from type_check import *
    File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py”, line 8, in
    import numpy.core.numeric as _nx
    File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py”, line 5, in
    import multiarray
    ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): Symbol not found: _PyCapsule_Import
    Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so
    Expected in: flat namespace
    in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so

    Any idea on how to fix that?

    1. What’s probably happening is that the script is running with the wrong Python. There is a line at the very top of your script that probably looks something like #!/usr/bin/python or similar. Make sure that it says #!/usr/bin/env python and it should automatically select the right Python.

      You shouldn’t need to modify the PYTHONPATH. I think the Python installer does that automatically for you.

      So, make sure the script has #!/usr/bin/env python at the top and try again.

  2. Erisa says:

    uh thanks, that was it :)
    Saved me a lot of monkey work, since as a workaround i was using the .py python file not the script

      1. kb1313 says:

        I am a neophyte Python user trying to set up NUMPY and SCIPY so I can try TAPPY. Like Erisa I’m getting an error at the multiarray.so line, although it’s a different error . I have Mac OSX 10.6.8, installed Python 2.7.3, then the NUMPY and SCIPY versions as above. When I run import nimby within python, I get the following:

        >>> import numpy
        Traceback (most recent call last):
        File “”, line 1, in
        … [deleted a few lines here]
        File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py”, line 5, in
        import multiarray
        ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find:
        /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper

        I don’t understand the error, as the filenames it was looking for and did find look the same. When I open up preferences within the Python Launcher that was installed, there seems to be something related to the fix above: in settings for Python Script, the line for interpreter reads “/usr/local/bin/pythonw” and there is no check at a box to allow override with #! in script. If I change either of those, will it help? (And what does the w at the end of python mean?)

        Many thanks for any help you can give me!

      2. I think this means that the installed numpy does not match the installed Python. You must take some care when downloading the installers so that they match the Python you installed and your OS version. For example, at the NumPy 1.6.2 download page there is an installer for Python 2.7 and Mac OS 10.6 that is probably your best bet (see http://sourceforge.net/projects/numpy/files/NumPy/1.6.2/). Do you recall which NumPy installer you downloaded? The same advice goes for choosing the SciPy and matplotlib installers as well.

        I’m not sure you need to worry about anything in the Python Launcher. I’ve never even opened that.

      3. keir13 says:

        Many thanks for such a quick response! Your opening comment makes overall sense, but I did use the NumPy installer for Python 2.7 and OSX10.6 that you mention. In fact, I initially tried the “latest” installer at the top of the sourceforge page without noticing it is for 2.6, but when it wouldn’t install at all I realized the issue and went to proper installer. However, your initial recommendation at the top of this thread was for installing Python 2.7.2. Maybe if I try deleting 2.7.3 and installing the slightly older version, that will solve the incompatibility issue.
        Thanks again

      4. If you’re confident you have a match between your Python and NumPy versions then I’m not sure what’s going on. The difference between 2.7.2 and 2.7.3 shouldn’t matter. The only thing I can recommend is starting over, or maybe going with one of the all-in-one installers for scientific Python. More info on that here: https://penandpants.com/install-python/.

  3. Dylan says:

    Hi there, I was wondering if you could assist me with the following problem? I’m completely new to Python and I might need some ‘hand holding’ to guide me through the installation process. I’m operating on Mac (Snow Leopard) and I have installed Python and its libraries as per suggested above. I believe I have installed iPython and Pandas on the system as well but whenever I tried to launch iPython notebook on the terminal using ‘ipython notebook’, it returns this list of error(?) to me:

    Traceback (most recent call last):
    File “/usr/local/bin/ipython”, line 8, in
    load_entry_point(‘ipython==1.0.dev’, ‘console_scripts’, ‘ipython’)()
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/frontend/terminal/ipapp.py”, line 390, in launch_new_instance
    app.initialize()
    File “”, line 2, in initialize
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/config/application.py”, line 84, in catch_config_error
    return method(app, *args, **kwargs)
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/frontend/terminal/ipapp.py”, line 315, in initialize
    super(TerminalIPythonApp, self).initialize(argv)
    File “”, line 2, in initialize
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/config/application.py”, line 84, in catch_config_error
    return method(app, *args, **kwargs)
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/core/application.py”, line 323, in initialize
    self.parse_command_line(argv)
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/frontend/terminal/ipapp.py”, line 310, in parse_command_line
    return super(TerminalIPythonApp, self).parse_command_line(argv)
    File “”, line 2, in parse_command_line
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/config/application.py”, line 84, in catch_config_error
    return method(app, *args, **kwargs)
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/config/application.py”, line 435, in parse_command_line
    return self.initialize_subcommand(subc, subargv)
    File “”, line 2, in initialize_subcommand
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/config/application.py”, line 84, in catch_config_error
    return method(app, *args, **kwargs)
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/config/application.py”, line 367, in initialize_subcommand
    subapp = import_item(subapp)
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/utils/importstring.py”, line 40, in import_item
    module = __import__(package,fromlist=[obj])
    File “/Library/Python/2.6/site-packages/ipython-1.0.dev-py2.6.egg/IPython/frontend/html/notebook/notebookapp.py”, line 41, in
    from jinja2 import Environment, FileSystemLoader
    ImportError: No module named jinja2

    Additionally, how do I go about checking if iPython and Pandas are actually installed in my system? Really appreciate your help. Thank you.

    D

  4. frenchie says:

    Hello, I am using SciTE to write my code in Python. I’m a student,so numpy and matplotlib are going to be very helpful. I have installed all the packages mentionned above. But when writting: “import numpy” a message appears in the output.

    “shell-init: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted”

    I don’t understand. Does this mean I can’t have numpy synchronised with SciTE??? In my school, we are using SciTE so I don’t want to go for another software.

      1. Frenchie says:

        Thanks for the answer. The thing is: numpy works because in the terminal everything goes well. But on SciTe it always prints the same message. “… Operation not permitted”. Do you know what it means and how i can fix that?

  5. ryanhuges4500 says:

    Hi, I’ve installed Numpy, Matplotlib and scipy. Every time I try importing pylab I get the following error:
    Python 2.7.4 (default, Sep 26 2013, 03:20:26)
    [GCC 4.7.3] on linux2
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> import numpy,matplotlib,scipy
    >>> import pylab
    Traceback (most recent call last):
    File “”, line 1, in
    File “/usr/lib/pymodules/python2.7/pylab.py”, line 1, in
    from matplotlib.pylab import *
    File “/usr/lib/pymodules/python2.7/matplotlib/pylab.py”, line 222, in
    from matplotlib import mpl # pulls in most modules
    File “/usr/lib/pymodules/python2.7/matplotlib/mpl.py”, line 2, in
    from matplotlib import axis
    File “/usr/lib/pymodules/python2.7/matplotlib/axis.py”, line 13, in
    import matplotlib.scale as mscale
    File “/usr/lib/pymodules/python2.7/matplotlib/scale.py”, line 7, in
    from matplotlib.ticker import (NullFormatter, ScalarFormatter,
    File “/usr/lib/pymodules/python2.7/matplotlib/ticker.py”, line 126, in
    import decimal
    File “/usr/lib/python2.7/decimal.py”, line 3743, in
    _numbers.Number.register(Decimal)
    AttributeError: ‘module’ object has no attribute ‘Number’
    >>> export PYTHONPATH=”/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH
    File “”, line 1
    export PYTHONPATH=”/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH
    ^
    SyntaxError: invalid syntax
    >>> import pylab
    Traceback (most recent call last):
    File “”, line 1, in
    File “/usr/lib/pymodules/python2.7/pylab.py”, line 1, in
    from matplotlib.pylab import *
    File “/usr/lib/pymodules/python2.7/matplotlib/pylab.py”, line 222, in
    from matplotlib import mpl # pulls in most modules
    File “/usr/lib/pymodules/python2.7/matplotlib/mpl.py”, line 2, in
    from matplotlib import axis
    File “/usr/lib/pymodules/python2.7/matplotlib/axis.py”, line 13, in
    import matplotlib.scale as mscale
    File “/usr/lib/pymodules/python2.7/matplotlib/scale.py”, line 7, in
    from matplotlib.ticker import (NullFormatter, ScalarFormatter,
    File “/usr/lib/pymodules/python2.7/matplotlib/ticker.py”, line 126, in
    import decimal
    Could you tell me how to fix this please?

    File “/usr/lib/python2.7/decimal.py”, line 3743, in
    _numbers.Number.register(Decimal)
    AttributeError: ‘module’ object has no attribute ‘Number’

  6. Shraddha says:

    Just starting out with Python and needed all these libraries installed for a machine learning workshop. Thank you, this post really helped.
    I am running os x 10.7 and had Python 2.7.1 installed. Using “pip install numpy scipy” followed by “pip install matplotlib” resulted in a dependency error (numpy installed was < 1.6, which was needed for matplotlib).

    Started afresh with the above and seems to be working.

    Thanks!

Leave a comment

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