With every project you write in python, you will have different libraries that you lean on. Some projects might use the same library, but different versions. For this reason, the Python library virtualenv
was created. To enable a developer to quickly create new environments.
Every virtualenv
instance comes with pip
installed, which is a package manager for python. This allows you to do install packages like so.
pip install django
With pip
, it would be:
pip install virtualenv
Or from source. In this case, for virtualenv 1.10:
curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.10.tar.gz
tar xvfz virtualenv-1.10.tar.gz
cd virtualenv-1.10
[sudo] python setup.py install
I like to set the virtual env directory as a hidden directory.
virtualenv .penv
To activate the virtualenv
source .penv/bin/activate
Start installing packages
pip install django
View the packages you have installed
pip freeze
Save dependencies to a file, so that you can recreate the environment later.
pip freeze > requirements.txt
The next person who uses the project can then:
cd ~/project/dir/
virtualenv .penv
source .penv/bin/activate
pip install -r requirements.txt