Recently I had to reinstall Python with scientific tools on Mac OS X 10.8.
These are instructions that I read from the Internet to successfully install Python. [1,2]
PART I: Installing Python
Step 1. Remove old Python
We have to remove all previous installations of Python, except for the system’s Python distribution. Here’s the command to search our computer for Python.
1 |
find / -name *python*
|
We should remove other installed instances of Python except the one installed in /System.
Step 2. Install XCode Developer Tools
Now that we removed other copies of Python, it’s a good idea to install the latest Developer Tools from XCode. Go ahead and open XCode > Preferences to install those tools.
Step 3. Homebrew
We will use a wonderful packaging system for Mac, homebrew, to help us through the remainder of the process. The command for installing homebrew is:
1 |
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
|
Step 4. Modify Terminal Path
We must modify our path to accept homebrew-installed applications. This file is ~/.bashrc or ~/.bash_profile. See which file has stuff already in it.
1 |
export PATH=/usr/local/bin:$PATH
|
Another option is to modify /etc/paths directly. Mine looks like this:
1
2
3
4
5
6
|
/usr/local/bin
/usr/local/sbin
/usr/bin
/usr/sbin
/bin
/sbin
|
Step 5. Install Python
Python should be installed. –framework suffix ensures that Python is installed in the “Mac” way instead of the UNIX way.
1 |
brew install python --framework
|
Step 6. Python on the Path
After installing python, it has to be added to the path. Let’s edit ~/.bashrc or ~/.bash_profile to add another line:
1 |
export PATH=/usr/local/share/python:$PATH
|
Step 7. Update Python tools
Pip’s installation of Python tells us to update pip and distribute.
1
2
|
pip install --upgrade pip
pip install --upgrade distribute
|
Step 8. Virtual environments for Python
Let’s install virtualenv.
1 |
pip install virtualenv
|
Step 9. Virtualenv on the Path
Go back to ~/.bashrc or ~/.bash_profile and add virtualenv to the path. Here’s 3 more lines to add:
1
2
3
4
5
|
...
export WORKON_HOME=$HOME/Envs
export PROJECT_HOME=$HOME/Devel
source virtualenvwrapper.sh
...
|
PART II: Installing Scientific Python
Step 10. Install NumPy.
1 |
pip install numpy
|
Step 11. Install SciPy.
1
2
|
brew install gfortran
pip install scipy
|
Step 12. Install matplotlib.
1
2
|
brew install pkg-config
pip install matplotlib
|
Step 13. Install IPython.
1 |
pip install ipython
|
References
[1] https://python-guide.readthedocs.org/en/latest/starting/install/osx/ [2] http://penandpants.com/2012/02/24/install-python/