Most libraries get updates on a daily basis. As they grow it becomes harder for software developers to catch up with the new documentation and a really small and diminutive change can make your apps obsolete.
You like your apps the way they are, you don´t want to change them but with or without you the software world progresses and you will have to update or get behind.
Maybe you need to work in two projects at the same time and one uses outdated technology. Does it mean that you will have to update and downgrade the libraries every time you want to test something? Well, yes and no. You can do it, but you don’t have to if you use a virtual environment.
virtualenv is the right tool for you. It solves the “Project B depends on version 2.x but, Project C needs 11.2x” dilemma, and keeps your global site-packages directory clean and manageable by creating isolated Python environments. Each one with its own installation directories and doesn´t share libraries with the other environments you set. So you can have as many as you want, or as many as your hard drive allows you to.
To install you just need to run in your terminal:
sudo pip install virtualenv
To set it up you will basically use one main command that creates a directory with all the tools you’ll need.
It includes inside an activation script so that you can change your $PATH to the bin/ directory.
Every command or script you run from now on will be acting for that specific env or if you prefer you can run your scripts without using active if you call them from inside your bin/ directory.
If you want to exit the virtualenv just deactivate it with:
Also if you want other people to run your specific app you can list all the packages you are using in your virtualenv with:
pip freeze > requirements.txt
And install them with:
pip install -r requirements.txt
If you are not very convinced about virtualenv you can use it with virtualenvwrapper, an extension that makes it much more easier and organized. It also places all your virtual environments in one place.
To install just:
pip install virtualenvwrapper
You can now create virtual environments with:
Work on a virtual environments with:
Deactivate with deactivate as well but you can now delete with:
Other useful commands¶
List all of the environments.
Navigate into the directory of the currently activated virtual environment, so you can browse its site-packages, for example.
Like the above, but directly into site-packages directory.
Shows contents of site-packages directory.