Virtual Environment tool (virtualenv) is used to isolate different projects and their dependencies by creating individual python environments for each of them. It's like installing a package locally (and not globally), similar to npm package installation option. Following is an example to install and test virtualenv for creating two projects (Project1-A Django application and Project2- A Flask application):
$ virtualenv --version
$ pip install virtualenv(for Mac and Linux) or
$ sudo apt-get install python-virtualenvfor Ubuntu,
easy_installfor Windows to install the python environment.
$ mkdir Project1and
$ cd Project1
$ virtualenv venvp1and this would create a venvp1 folder inside Project1 directory.
source venvp1/bin/activate(if Linux) and
venvp1\Scripts\activate(if Windows) and prompt will change to
pip install Djangoto install Django for project1 and
deactivate(if needed) to return to the global environment.
pip install Flaskto install Flask.
Once above steps are executed (without any errors) one could (possibly and) simultaneously work between both environments without any conflicts.
--no-site-packagesexcludes the globally installed packages.
$ pip freeze > installedpkgp1.txt. This text file contains list of installed packages (including their versions) in the current environment. If there comes a need to deploy same environment at different folder (or machine) simply executing the command
$ pip install -r installedpkgp1.txtwould create same environment.
lsvirtualenv- list of all environments
cdvirtualenv- goto currently activated virtual environment
cdsitepackages- like previous, but goes directly to
lssitepackages- shows content of