wiki:InstallPythonOnMac

Apple pre-installs Python to Mac OS X since 10.8. Some some reasons you may want to install another Python:

  • When using the bundled Python upgrading OS X can nuke your Python packages, forcing you to reinstall them.
  • As new versions of Python are released, the Python bundled with OS X will become out-of-date. Homebrew always has the most recent version.
  • Apple has made significant changes to its bundled Python, potentially resulting in hidden bugs.
  • Homebrew’s Python includes the latest Python package management tools: pip and Setuptools

(Notes: the reasons are copied from Python Development Environment on Mac OS X Mavericks 10.9)


Install Python by Homebrew

The following is about how to use Homebrew to install Python (2.7.x) on Mac OS X (tested in 10.10). You can install this type of Python without uninstalling the pre-installed Python.

Step 1 - Basic Installation

# Installs Python with openssl support; "pip" and "setuptools" will be installed by default
brew install python --with-brewed-openssl

# Installs "IDLE.app" and "Python Launcher.app" in "/Applications"
brew linkapps python

# Updates "pip" and "setuptools" to the latest
pip install --upgrade pip setuptools

Step 2 - Further Steps (optional)

  1. Install Virtualenv
    pip install virtualenv
    
  1. Restricting pip to virtual environments

Add this to "~/.bash_profile" (then you have to use "gpip" instead of "pip" when you are in the global Python environment instead of a one created by Virtualenv.)

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

gpip(){
   PIP_REQUIRE_VIRTUALENV="" pip "$@"
}


Reference

See also

Last modified 3 years ago Last modified on May 3, 2015, 1:57:04 AM