News

New paper! in the American Naturalist

Wednesday, July 13, 2022

Python package control with virtual environment

It is very useful to keep track of which packages (of which versions) that you have used for what project.

For python, we can do it as follows on Linux and Unix:
First, if the python version you want to use has not been installed, install it. Then,

for Python3,
$python3 -m venv name_of_project

for Python2
$ virtualenv my_project
or to specify the version 2.X.X..
$ virtualenv -p /usr/bin/python2.7... name_of_project

("name_of_project" is the name that you are giving to the new folder that contains the virtual environment.)

Then, 
$ source my_project/bin/activate
will start the virtual environment. 

$ deactivate
will deactivate the current virtual environment.

$ pip freeze : to see the packages installed in the current virtual environment.

If you install packages using pip while being the virtual environment, they will be all installed and recorded together in the environment.