Python, pip, virtualenv environment via MacPorts
During the course of my day job, I needed to install Python and pip. For those using MacPorts, below is the method I’ve used to accomplish the task. I used Python v2.7 since I hear v3 has some backward compatibility issues.
For each component, I perform a search
, install
, select --list
and then select --set
.
Python
Search available Python versions
Install Python v2.7.8
From the list of Pythons that show up, I chose to install python27:
List installed Pythons
A number of Apple installations should show up along with the Python that was installed in the last step (python27)
Set active Python version
Set the MacPorts Python 2.7.x installation as the default Python system-wide:
pip
Search available pip versions:
Install pip v1.5.6
List installed pips
Note: If you get an error executing the above, try forcing the activation by executing sudo port -f activate py27-pip
Set active pip version
virtualenv
Search available Python virtual environments
Install virtualenv 1.11.6 for Python v2.7
List installed virtualenvs
Set active virtualenv
Following the above should give you Python, pip and virtualenv for Python 2.7.
As a bonus, MacPorts also ensures there’s an easy_install
version that’s specific to your MacPorts Python installation. In the above case, it should be located in <MacPorts_Home>/bin/easy_install-2.7
. If you can’t remember the location of your MacPorts home directory, you can use bash completion by having it complete easy_install
.