Setup Python Virtualenv
Using virtualenv with the different versions of python:
This works with Debian (and it's children (Ubuntu)) and MacOS.
ArchLinux has adopted Python 3 as the default so python = Python 3.
To check, run python from the command line.
If you see something like:
Python 2.7.3 (default, Apr 24 2012, 00:00:54) [GCC 4.7.0 20120414 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
Then you know Python 2 is installed.
Now run python3 from the command line.
If you see something like:
Python 3.2.3 (default, Apr 23 2012, 23:14:44) [GCC 4.7.0 20120414 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
Then you know Python 3 is installed.
Structure:
$HOME/dev/python
$HOME/dev/python/python2
$HOME/dev/python/python3
Install virtualenv and virtualenvwrapper:
sudo pip install virtualenv sudo pip install virtualenvwrapper
Go to ~/dev/python and create a new directory:
mkdir .virtualenvs
This is where the virtualenv will actually be stored.
Modify .bashrc by adding the following lines:
# Adding virtualenvwrapper export WORKON_HOME=$HOME/dev/python/.virtualenvs export PROJECT_HOME=$HOME/dev/python/python2 source /usr/bin/virtualenvwrapper.sh
close the terminal and reopen (sourcing doesn't seem to work)
Run: workon once to initialize the environment.
This is using the virtualenvwrapper program:
All development is in ~/dev/python/python2 or ~/dev/python/python3
For Python2:
-
Create the directory for the project:
cd ~/dev/python/python2/ mkdir mynewproject cd mynewproject
-
Create the virtualenv:
mkvirtualenv -a $PWD -p /usr/bin/python mynewproject
For Python3:
-
Create the directory for the project:
cd ~/dev/python/python3/ mkdir mynewproject cd mynewproject
-
Create the virtualenv:
mkvirtualenv -a $PWD -p /usr/bin/python3 mynewproject