Posted on Wed 16 January 2013

Python development environment

Few weeks ago I spent ten days building simple web application on top of Tornado web-server and ElasticSearch. There are some tips I learnt for setting comfortable environment for python development.

  1. Do not mess with global packages, use virtualenv.
  2. Do not mess with virtualenvs, use virtualenvwrapper.
  3. Do not mess with packages from system repositories, use pip.
  4. Do not mess with python’s interactive prompt, use ipython.

Everything is so simple but I could not imagine searching for such tools without help of senior developer.

You can have several python projects to develop. If you try to use your global system scope to satisfy all requirements of your projects you will end up with messed packages, cause different projects might require different versions of same package and some other minor issues. virtualenv creates separate scope for every project.

virtualenv is an excellent tool, but it can become even better. It is easy to use but still requires a lot of routine commands. virtualenvwrapper solves this problem. It creates bunch of useful aliases so managing virtual environments become a piece of pie.

How do you install python libs? Do you download source/binaries and put pieces together manually? Maybe you are newbie and like to install everything using system repositories (apt-get, yum or brew) as I loved before. The right way for python related packages is using easy_install or pip (everybody says last is better). The awesome part is - it works great with virtualenv and makes life much easier. You can get different versions of same package. You can easily get list of all packages installed in current environment running pip freeze and then use output to deploy (e.g. Heroku uses requirements.txt file generated by pip freeze to read dependencies).

Last thing. As a unexperienced developer I faced such situation a lot of times: I want to try some piece of code, but I do not want run whole project for that, instead I run REPL. The problem is python default REPL doesn't even provide code completion. IPython is a great project which can help you in this. It provides very customized REPL with all good stuff you can imagine: code completion, auto-intend, inspector of any python object, built-in magic commands and much more. In latest versions it is not just good REPL anymore, check out there IPython Notebook which awersome.

As for now, I feel really good in such environment and hope I do not waste much time on typing and debugging but on actual building things.

© Slava Kim. Built using Pelican. Theme by Giulio Fidente on github. .