Pip and Virtualenv are the packaging tools recommended by the Python Packaging User Guide. Use Pip to install Python packages from PyPI, and virtualenv to isolate application specific dependencies from a shared Python installation.
To install Pip on a Mac OS, follow the Pip installer instructions:
Install or Upgrade pip To install or upgrade pip, securely download get-pip.py. [1]
Then run the following (which may require administrator access):
$ python get-pip.py
If setuptools (or distribute) is not already installed, get-pip.py will install setuptools for you. [2]
On Debian, Ubuntu, and Fedora Linux, Pip is available under the name python-pip
.
On Debian and Ubuntu:
$ sudo apt-get install python-pip
On Fedora:
$ sudo yum install python-pip
Install Virtualenv tools.
$ sudo pip install virtualenv
Change into your Python project directory (for example, “my-project”), then create a new virtual environment. Naming it .venv
will create a hidden folder to contain the necessary files in.
$ cd my-project
$ virtualenv .venv
Activate the environment.
$ source .venv/bin/activate
(if you use the bash shell)$ source .venv/bin/activate.csh
(if you use the csh or tcsh)
Now which python
should confirm that your python executable is located under .venv
. Your shell prompt might also be modified to include “my-project”.
When you're done working with your virtual environment, it is easy to get out.
$ deactivate
If you are installing an existing project, look for a requirements.txt file containing names of packages required by the project. Ask Pip to install the list of packages.
$ pip install -r requirements.txt
You may want to have a virtual environment auto-activate when you enter a directory. Cody Soyland has produced a short guide for users of the bash shell.