Home » programming » Virtualenv

Virtualenv

Problem

You want to install/test a library for Python but you don’t want it to interfere with the rest of the system.

You want different installation of Python and sets of libraries at the same time on your system. You also want the ability to switch from one to the other.

You are a robot (or a mathematical statement) and you have started enumerating all the possible things that you can do with your computer. Present one of those.

All these problems have a common solution.

Solution

Setup

  1. Install virtualenv using your package manager
  2. mkdir ~/virtual_env
  3. virtualenv ~/virtual_env/virt1

You can create more than one virtual environment by choosing different directories.

Activation

  1. source ~/virtual_env/virt1/bin/activate

Now, you use the “special environment” that is described in virt1 dir. It may contain a different version of Python, libraries that do not exist system-wide etc…

Any installation that you do at these point using tools such as pip, easy_install etc affects only this special environment.

For instance:
pip install requests

Deactivation

  • deactivate
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: