- Before beginning, you should have a version of pip installed. If you don't, it is recommended you install it universally via the Terminal:
sudo easy_install pip
- Once you do, install virtualenvwrapper:
sudo pip install virtualenvwrapper
. More information can be found in Read the Docs - Change into the directory where your new project is; e.g.,
cd ~/Documents/Repos/my_new_project
- Create your new environment in this directory, automatically giving it the name of the current directory:
thisdir=${PWD##*/};mkvirtualenv -a . -r requirements.txt $thisdir
- To make sure you remember what your virtual environment is named (and, indeed - all you have created), execute
lsvirtualenv
which lists all virtual environments. - To make sure you're in the virtual environment, execute:
workon my_new_project
(where the last bit is your virtual environment name).
If you want to "start over" in a virtual environment by removing all Pip-installed packages, the easiest way to do it is execute:
pip freeze | xargs pip uninstall -y
For Python 3 and Pip 3, you'll need to do this:
pip3 freeze > uninstall_requirements.txt; pip3 uninstall -r uninstall_requirements.txt
Cool! I am trying now pipenv. Sofar looks good.