Setup Python on Mac OS 10.8 (Mountain Lion)
The first and most important step of setting up a python development environment is setting up a virtual environment for everything you do and your install tools.
Setup install and virtual environment tools
pip
and distribute
are python installer tools.
virtualenv
and virtualenvwrapper
are virtual environment tools.
-
Install
pip
anddistribute
.sudo easy_install pip curl -O http://python-distribute.org/distribute_setup.py sudo python ./distribute_setup.py rm ./distribute_setup.py
-
Install
virtualenv
andvirtualenvwrapper
.sudo pip install virtualenv sudo pip install virtualenvwrapper
-
Add
source /usr/local/bin/virtualenvwrapper.sh
to~/.bash_profile
echo source /usr/local/bin/virtualenvwrapper.sh >> ~/.bash_profile source .bash_profile
By default, your virtual environments will be stored in ~/.virtualenvs/. Customize by setting a WORKON_HOME
environment variable.
Starting a new python project
Anything you work on or install should be done through a virtual environment created for your project. Virtual environments an be created and deleted at will without effecting another project.
From now on, you should only pip install
when you have a virtualenv active.
Basic Commands
Full documentation is available on readthedocs.org.
mkvirtualenv my_project # create new project
workon my_project # switch projects
deactivate my_project # return to system python
rmvirtualenv my_project # remove project
cdsitepackages # cd to python site-packages
lssitepackages # ls python site-packages