The following are the steps I take to setup up VirtualEnv and VirtualEnvWrapper on a new machine.
-
Make sure pip is installed by running pip in the terminal.
-
If it isn’t installed, install by doing
1
|
|
- Next, install virtualenv and virtualenvwrapper
1
|
|
1
|
|
- Open up your .bash_profile or .profile, and after your PATH statement, add the following
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
-
Open a new terminal window. You should see virtualenvwrapper.sh being run and setting up your .virtualenvs directory.
-
Test creating a new virtualenv
1
|
|
- You should see something in the console like
1 2 3 4 5 6 7 8 |
|
-
That should put you into a new virtualenv called “testenv”
-
Lets install some packages and create a requirements.txt file
1 2 3 4 |
|
-
Your have just installed 3 python packages into your virtual environment, and created a .txt file that will have all the necessary information in order to reproduce your environment.
-
You can leave your virtualenv by doing
1
|
|
- To create a new virtualenv, and install the libraries based on the requirements.txt file you just created, just do the following.
1 2 |
|
- List of commonly used commands
- mkvirtualenv (create a new virtualenv)
- rmvirtualenv (remove an existing virtualenv)
- workon (change the current virtualenv)
- add2virtualenv (add external packages in a .pth file to current virtualenv)
- cdsitepackages (cd into the site-packages directory of current virtualenv)
- cdvirtualenv (cd into the root of the current virtualenv)
- deactivate (deactivate virtualenv, which calls several hooks)