All I want to do is. . .

. . .install a scientific Python environment (numpy + scipy + matplotlib) on MacOSX without Enthought.

OS:
Tags:

Python has many excellent libraries for scientific computing. Unfortunately, installing these libraries can be a yak shaving nightmare. One solution is to download the Enthought Python Distribution, a Python distribution that comes bundled with a large number of packages precompiled. While the EPD may be the best solution to get off the ground with scientific computing in as little time as possible, problems may arise when (1) you want to use python outside of the EPD environment, possibly with diffent Python versions and (2) you want to keep your scientific environment in a virtualenv.
Contributors: sloria Updated: 07/14/13

Do these first:

  • Install Homebrew
    # In your Mac Terminal, run:
    $ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
    
    # In your ~/.bashrc, ~/.bash_profile, or ~/.zshrc (for zsh users)
    # ...
    export PATH=/usr/local/bin:$PATH
    
    $ brew doctor
    
     [full instructions]
  • Install Python 2 and/or 3
    # On Mac >= 10.5 with homebrew
    $ brew update
    ## Install Python 2
    $ brew install python
    ## Install Python 3
    $ brew install python3
    ## Follow any instructions that appear after each brew install
    
    # Is everything working?
    $ brew doctor
    # Listen to the doctor
    
    # Run Python 2
    $ python
    # Run Python 3
    $ python3
    # Install a Python 2 package
    $ pip install some-package
    # Install a Python 3 package
    $ pip3 install some-package
    
     [full instructions]
  • Install the latest Mac C and C++ compilers
    # Get the latest version of Xcode from the Mac App Store
    # Here: https://developer.apple.com/xcode/
    
    # Open Xcode, then press `Command + ,` to open preferences
    
    # Click `Downloads` at the top of the window
    # Then click `Install` next to `Command Line Tools`
    
     [full instructions]

Optional (but recommended) first step: Create a new virtual environment

# If you're using virtualenvwrapper
$ mkvirtualenv science
$ workon science

Numpy, Scipy, and Matplotlib

Install a fortran compiler and Freetype.

$ brew update
$ brew install gfortran freetype
# Remember to follow any instructions that show up after each install
# To display the instructions again, run `brew info gfortran` or `brew info freetype`

Install the Python packages.

# Order matters!
$ pip install numpy
$ pip install scipy
$ pip install matplotlib
# Optional: install ipython
$ pip install ipython

If everything works, you should be able to import pylab, which will bring numpy, scipy, and matplotlib functionality all in one go.

# Check that everything works
$ python
>>> import pylab

If all you need is numpy, scipy, and matplotlib, you're done!

Bonus: Install the rest of the EPD packages

If you want to install more of the libraries included with EPD, you can try making a requirements.txt file containing the following:

# requirements.txt
# This includes all the packages bundled with EPD-Free
# Feel free to add/remove any items
appinst>=2.1.1
apptools>=4.1.0
casuarius>=1.0
chaco>=4.2.0
cloud>=2.4.6
configobj>=4.7.2
distribute>=.6.26
enable>=4.2.0
enaml>=0.2.0
enstaller>=4.5.1
etsproxy>=0.1.1
freetype>=2.4.4
ipython>=0.12.1
jinja2>=2.6
libjpeg>=7.0
libpng>=7.0
matplotlib>=1.1.0
nose>=1.1.2
numpy>=1.6.1
PIL>=1.1.7
ply>=3.4
pyaudio>=0.2.4
pyface>=4.2.0
pyglet>=1.1.4
pygments>=1.4
python_dateutil>=1.5
pytz
pyzmq>=2.1.11
scipy>=1.74
tornado>=2.2
traits>=4.2.0
traitsui>=4.2.0
wxPython>=2.8.10

Then run:

$ pip install -r -U requirements.txt

NOTE: This step has not been verified. It is possible that some of the packages have other non-Python dependencies that need to be installed first.

See also:

Raw: scientific-python.md


If you have suggestions, corrections, or content to contribute, fork us at our Github repo or open an issue.

Licensed under the CC-SA.