PIP setup on Python 3

I have three versions of python on my Mac

  • Default system python
  • python.org's Python 2.7.7
  • python.org's Python 3.4.1

I leave the default installation completely alone. The python 2.x is for all legacy code Python 3.x is my main development environment since it is the future of Python.

~.bash_profile

.bash_profile located in your home directory is important to set up python.

--> cat .bash_profile
# Setting PATH for Python 3.4

# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:~/bin:${PATH}"
export PATH

# Setting PATH for Python 2.7.7 from python.org
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

# settings from:
#   http://hackercodex.com/guide/mac-osx-mavericks-10.9-configuration/
#   http://hackercodex.com/guide/python-development-environment-on-mac-osx/

# Set architecture flags for 64 bit
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc

# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true
# cache pip-installed packages to avoid re-downloading

My bash profile consists of modifying the path to allow python.org's Python 2.7.7 and Python 3.4.1 to run: To run Python type

  • python - runs the default system python
  • python2 - runs Python 2.7.7 from python.org
  • python3 - runs Python 3.4.1 from python.org

The problem with having so many pythons is if you install a module with PIP how do you know which python is it being installed into?

My solution: virtual environments

I never install any modules into any of the python installations. I always create a new virtual environment for each program But since PIP is installed in all of my pythons it would be easy to accidentally install a module when you are not running a virtual environment.

Solution:

# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true

References:

http://hackercodex.com/guide/mac-osx-mavericks-10.9-configuration/

http://hackercodex.com/guide/python-development-environment-on-mac-osx/