Saturday, May 5, 2012

Python development environment for Ubuntu 12.04 Precise

Frankly, my upgrade for the newest release of Ubuntu 12.04 Precise broke my OS. And I didn't have any chance to recover it. So I just reinstalled Ubuntu and got fresh, but empty operation system. The last time when I did setup of Python development environment was one year ago. All my notes about this things were old and unsuitable for the latest Ubuntu release. This post is summary of my actions to setup Python development environment from scratch.
Install Python setuptools package:
sudo apt-get install python-setuptools python-pip
Install virtualenvwrapper:
sudo pip install virtualenvwrapper
Setup virtualenvwrapper:
mkdir -p ~/.virtualenvs
echo 'export WORKON_HOME=~/.virtualenvs' >> ~/.bashrc
echo 'export DJANGO_SITES_ROOT=$HOME/projects/' >> ~/.bashrc
echo 'source /usr/local/bin/virtualenvwrapper.sh' >> ~/.bashrc
source ~/.bashrc
Install Django extension for virtualenvwrapper. I have several Django projects, but if you aren't using Django, then you can skip this step:
sudo apt-get install git-core
mkdir -p ~/.virtualenvs/django-libs
cd ~/.virtualenvs/django-libs
git clone https://github.com/epicserve/django-environment.git
cd ~/.virtualenvs/django-libs/django-environment/django_env/bin/
install.py
Test virtualenvwrapper:
cd ~/projects
mkvirtualenv example
cd example && ls
Install PIL with JPEG, ZLib and FreeType support, if you aren't using PIL, then you can skip this step:
sudo apt-get install libjpeg62-dev zlib1g-dev libfreetype6-dev
cd ~/.virtualenvs/{project-name}
For 32-bit systems:
ln -s /usr/lib/i386-linux-gnu/libz.so ./lib/
ln -s /usr/lib/i386-linux-gnu/libjpeg.so ./lib/
ln -s /usr/lib/i386-linux-gnu/libfreetype.so ./lib/
For 64-bit systems:
ln -s /usr/lib/x86_64-linux-gnu/libz.so ./lib/
ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so ./lib/
ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so ./lib/

pip install PIL
I'm big fan of Vim, so here is steps for Vim also:
sudo apt-get install vim.gtk
Install Pathogen plugin:
mkdir -p ~/.vim/autoload ~/.vim/bundle
curl -so ~/.vim/autoload/pathogen.vim https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim
add to ~/.vimrc file:
call pathogen#infect()
Install Fugitive for Git support and Python-mode for all Python stuff in Vim:
cd ~/.vim/bundle
git clone git://github.com/tpope/vim-fugitive.git
git clone git://github.com/klen/python-mode.git
Install super-fast Command-T plugin for opening files in Vim:
cd ~/.vim/bundle
git clone git://git.wincent.com/command-t.git
cd ~/.vim/bundle/command-t
rake make
That's all folks. I will keep this post updated for a while.
And If you have any comments and suggestions, please, post them in comments. Thanks.

2 comments:

  1. Hi Andrey,
    I remember going through a lot of grief trying to install PIL in virtualenv. I wanted to enable jpg support and I remember fiddling with soft links in order to enable it. Later I found that there is "Pillow" (http://pypi.python.org/pypi/Pillow). Everything was discovered and work correctly after "pip install pillow". It is drop-in replacement for PIL. Everything works as in PIL. I didn't have to change any code (from PIL import Image).
    Cool vim setup. I should look into it.

    ReplyDelete