sudo pip install virtualenv
see help:
virtualenv -h
By default a new virtual environment is started with no packages installed. If you want to start with access to all system packages, start virtualenv with the --system-site-packages
flag.
cd to the folder you want to start a virtual environment in.
virtualenv foo
where foo is the name of your environment. This will create a virtualenv, but not activate it.
In order to activate, source the activate script:
source foo/bin/activate
To see the packages installed inside of our virtual environment:
pip freeze
to stop a virtualenv:
deactivate
The -p
flag is for the python interpreator to use. The default is the interpretor that python was installed with (/usr/bin/python)
start virtualenv with Python 3:
virtualenv -p python3 foobar
You odn’t really have to give it the full path, you can just say python3.
To check python version:
python --version
There are two ways to do it. One is to pass attributes to export command and the other is to config the virtualenv.ini file.
Take the attribute name, replaces all the dashes (-) with underscroes (_) and then prefixing that with VIRTUALENV_
For example, we are going to setup distribute
to be the default package management library that we are installing with our virtualenv.
export VIRTUALENV_DISTRIBUTE=TRUE
Now if you create a virtualenv it’ll install distribute by default. If you want this to be permanent, you can save the export statement to your ~/.bashrc or ~/.bash_profile or any of your startup scripts that you have.
The config file is supposed to in the ~/.virtualenv
folder which may not exist. To create and edit a
sudo mkdir ~/.virtualenv && touch ~/.virtualenv/virtualenv.ini && nano ~/.virtualenv/virtualenv.ini
Format:
[virtualenv]
python = python3
[/virtualenv]