Place this 3 lines in your ~/.bash_profile
file:-
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/work
source `which virtualenvwrapper.sh`
The $HOME
environment variable points to your user's home. Also known as the tilda "~", i.e. /Users/your_osx_username/
.
WORKON_HOME
is the new environment variable that you are assigning by using the export
call in your ~/.bash_profile
file. This is where all your newly created virtualenv directories will be kept.
PROJECT_HOME
is where you normally place all your custom project directories manually. Nothing to do with your virtualenvs per say but just an easy reference point for you to cd to using the cd $PROJECT_HOME
syntax.
which virtualenvwrapper.sh
points to the location where the bash script virtualenvwrapper.sh
is located and hence when you source it, the functions in that bash script becomes available for your mkvirtualenv
calls.
Whenever you open a "new shell" (new tab, close your current tab after you first update your ~/.bash_profile
file), all these environment variables and bash functions will be thus available in your shell.
When we create a new virtualenv using the mkvirtualenv -p python2.7 --distribute my_new_virtualenv_1
, what actually happens is that a new directory called my_new_virtualenv_1
containing a symlink to your global python2.7 is being created and new python site-packages sub-directory are created in your ~/.virtualenvs/
directory. Reference:-
calvin$ mkvirtualenv -p python2.7 --distribute my_new_virtualenv_1
Running virtualenv with interpreter /opt/local/bin/python2.7
New python executable in my_new_virtualenv_1/bin/python
Installing distribute..........................................................................................................................................................................................................done.
Installing pip................done.
virtualenvwrapper.user_scripts creating /Users/calvin/.virtualenvs/my_new_virtualenv_1/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/calvin/.virtualenvs/my_new_virtualenv_1/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/calvin/.virtualenvs/my_new_virtualenv_1/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/calvin/.virtualenvs/my_new_virtualenv_1/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/calvin/.virtualenvs/my_new_virtualenv_1/bin/get_env_details
So if you do
cd ~/.virtualenvs/my_new_virtualenv_1
calvin$ tree -d
.
├── bin
├── include
│ └── python2.7 -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
└── lib
└── python2.7
├── config -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
├── distutils
├── encodings -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings
├── lib-dynload -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
└── site-packages
├── distribute-0.6.28-py2.7.egg
│ ├── EGG-INFO
│ └── setuptools
│ ├── command
│ └── tests
├── pip-1.2.1-py2.7.egg
│ ├── EGG-INFO
│ └── pip
│ ├── commands
│ └── vcs
└── readline
You will see this directory structure in it.
Note of course that you are using Envs
and I am using .virtualenvs
to act as the virtual env holding directory.