Setup Python on Linux

Most Linux distributions include python with the base install, so installing Python won't be an issue. However, our tutorials and examples generally use pip and virtualenv which are generally not installed by default.

There are a lot of different Linux distributions out there and it would be impractical to write out instructions for all of them so I'm limiting this to Ubuntu (should also work on Debian) and Fedora (should also work on RHEL, CentOS and Scienfitic Linux).

Installing virtualenv and pip

Virtualenv and pip are offered as packaged for Ubuntu and Fedora so installing them is really easy.

Installing on Fedora

sudo yum install python-virtualenv python-pip

Note that the pip command is installed as pip-python (python-pip in F17+) and in order to use the 'pip' command by itself, you would need to do the following:

sudo ln -s /usr/bin/pip-python /usr/bin/pip

Installing on Ubuntu

sudo apt-get install python-virtualenv python-pip

Testing it Out

Now that everything is installed, it's time to test it out.

Testing virtualenv

Open a terminal and navigate to some directory under your home (assuming /home/monty/code)

You should now have an active virtualenv which is separate from the system libraries. Your command prompt should look something like

(env_test)[monty@system code]$

You can install whatever you want in the new virtualenv using pip:

(env_test)[monty@system code]$ pip install pytest
Downloading/unpacking pytest
  Downloading (527Kb): 527Kb downloaded
  Running egg_info for package pytest
Downloading/unpacking py>=1.4.12 (from pytest)
  Downloading (227Kb): 227Kb downloaded
  Running egg_info for package py
Installing collected packages: pytest, py
  Running install for pytest
    Installing py.test script to /home/monty/code/env_test/bin
    Installing py.test-2.7 script to /home/monty/code/env_test/bin
  Running install for py
Successfully installed pytest py
Cleaning up...

Testing Pip

On a Linux system, it's generally not a great idea to install Python packages with pip. Libraries installed outside of the package management system (apt for Ubuntu, yum for Fedora) can cause problems with upgrades and system consistency. Unless you have a really good reason to do otherwise, always install non-packaged libraries in a virtualenv.

SetupPythonOnLinux (last edited 2013-06-30 13:53:20 by ip202)