Preparing python environment - jlazic/GlogSMS GitHub Wiki

Install python, python development libs and libxml dependencies. Build-essential meta package will install all tools needed for compiling libxml and optionally postgresql connector for python.

sudo apt install python python-dev libxml2-dev libxslt1-dev lib32z1-dev build-essential

Now that you have python, you should install setuptools (https://pypi.python.org/pypi/setuptools) and pip (https://pypi.python.org/pypi/pip)

curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | sudo python -

and pip

curl https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py | sudo python -

Now that you have functional pip, use it to install virtualenv, and virtualenvwrapper

sudo -H pip install virtualenv
sudo -H pip install virtualenvwrapper

Virtualenv enables us to create isolated python environment, where every environment has it's own set of python libraries. Virtuelenvwrapper is set of bash scripts that make work with virtualenv more enjoyable. From now on all instalations will run under "normal" user account, and not with sudo/root.

Create directory to store your virtualenv's

mkdir ~/.virtualenvs

and add these line so end of your ~/.bashrc

export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

Run this, or logoff, and logon again to apply new settings in BASH

source ~/.bashrc

Create virtualenv

Using virtualenvwrapper create new virtual environment. You can call it whatever you like, I will use "sms"

mkvirtualenv sms

This will create new virtual environment, and activate it for you. You will notice that you PS1 prompt has been prepended with "(sms)", this is indicator that you are now in virtualenv environment. Feel free to be amazed with the fact that now you have independent python environment, ie.

(sms)josip@ubuntu:~$ which python
/home/josip/.virtualenvs/sms/bin/python

From now run all command inside this virtualenv. You can exit virtualenvironment using deactivate command, and activate it againg using workon sms command. You can read more about using virtualenv here: http://virtualenv.readthedocs.org/en/latest/