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.
Open a terminal and navigate to some directory under your home (assuming /home/monty/code)
- cd ~/code
- virtualenv --distribute env_test
- source env_test/bin/activate
You should now have an active virtualenv which is separate from the system libraries. Your command prompt should look something like
You can install whatever you want in the new virtualenv using pip:
(env_test)[monty@system code]$ pip install pytest Downloading/unpacking pytest Downloading pytest-2.3.4.zip (527Kb): 527Kb downloaded Running setup.py egg_info for package pytest Downloading/unpacking py>=1.4.12 (from pytest) Downloading py-1.4.12.zip (227Kb): 227Kb downloaded Running setup.py egg_info for package py Installing collected packages: pytest, py Running setup.py 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 setup.py install for py Successfully installed pytest py Cleaning up...
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.