Step-by-step python setup with pip and virtualenv?

Are there any good step-by-step tutorials on setting up a Mac to use the python, pip, and virtualenv settings?

+4
source share
2 answers

Download and install Python 2.7.1 Mac OS X x86-64 / i386 64-bit / 32-bit installer (for Mac OS X 10.6) or Python 2.7.1 32-bit i386 / PPC for Mac OS X (for Mac OS X 10.3 to 10.6) .

Installation instructions for virtualenv and pip on OS X

This is how I installed virtualenv and pip on OS X:

 curl -O http://peak.telecommunity.com/dist/ez_setup.py sudo python ez_setup.py sudo easy_install pip sudo pip install virtualenv 

I also like virtualenvwrapper with virtualenv , so I installed it using:

 sudo pip install virtualenvwrapper 

I originally took this information from Jesse Noller's article β€œSO DO YOU WANT TO USE A PYTHON ON A MAK?”

~/.bash_profile Settings

This is probably too much, but below is the Mac OS X section of my ~/.bash_profile . I have several versions of Python installed using the Python.org installers, so I am going through a for loop to add each version of Python.

 # Mac OS X specific settings if [ ${os_name} == 'Darwin' ]; then # The last Python added to PATH will be the default Python PY_VER=( '3.1' '2.6' '2.7') PY_VER_ELEMENTS=${#PY_VER[@]} DEFAULT_PY=${PY_VER[${PY_VER_ELEMENTS}-1]} PY_FW="/Library/Frameworks/Python.framework/Versions" for (( i=0;i<$PY_VER_ELEMENTS;i++)); do if [ -x ${PY_FW}/${PY_VER[${i}]}/bin/python${PY_VER[${i}]} ]; then PATH="${PY_FW}/${PY_VER[${i}]}/bin:${PATH}" export PATH fi done # Check for virtualenv in the default Python if [ -x ${PY_FW}/${DEFAULT_PY}/bin/virtualenv ]; then export VIRTUALENV_USE_DISTRIBUTE=true export WORKON_HOME=$HOME/.virtualenvs fi # Check for pip if [ -x ${PY_FW}/${DEFAULT_PY}/bin/pip ]; then export PIP_VIRTUALENV_BASE=$WORKON_HOME export PIP_REQUIRE_VIRTUALENV=true export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache fi # Enable virtualenvwrapper if [ -x ${PY_FW}/${DEFAULT_PY}/bin/virtualenvwrapper.sh ]; then source ${PY_FW}/${DEFAULT_PY}/bin/virtualenvwrapper.sh fi fi 
+8
source

What problems?

  • Install PIP: easy-install pip
  • Install virtualenv: pip install virtualenv
  • Create a virtual environment: virtualenv myenv
  • Enter on environment: source myenv/bin/activate or use myenv/bin/python
  • ???
  • PROFIT!
+2
source

All Articles