You work on multiple Python projects with different version of Python, libraries, framework, and packages. You’re looking for a better and simple way to manage them without having pain. If you are kind of person having those condition, this article may be helpful for you.
We can create an isolated environment for a specific Python project using virtualenv and pip. In each environment, you can specify version of Python, what packages, framework, libraries you are using in that project.
Install Easy Install
First of all, we need to install Easy Install (in case if you did not install it)
I’m using Ubuntu 13.10 for this example.
-U ensures to search the latest version and perform force upgrade.
Create Virtual Environment
Go to your project directory and create a virtual environment.
myenv is the name of your environment. You can change it with whatever you want.
You can also create virtual environment with different Python version.
Once you have a new virtual environment you can activate it by:
and deactivate it by:
One of usefull package to install is Yolk. Yolk is a tool to list what packages are installed in the current environment.
Installing package in virtual environment is simply using pip. Note: You need to activate the virtual environment before you do install.
1 2 3 4 5 6 7 8
Running yolk will return list of installed packages in the current environment.
Install Packages From Requirements File
If you have an existing project and you want to clone the project with the same
packages, you can create a requirements file using
This will create a file named
installing list of packages from the requirements file is very easy. Copy the
file into your new project directory and use this command:
Note: Installing and uninstalling package need to activate the virtual environment.
Now you can manage many different Python projects on your computer with any different Python versions, libraries, framework, etc.
Knowledge is power.