Taming the Komodo dragon for virtualenv and python
Although I still use textmate for quick edits I moved on to Komodo IDE some time ago. I'm not hardcore enough for vim, emacs, ed, cat, or butterflies and it did most of what I wanted it to do; autocomplete. calltips, mercurial, and git integration etc. Its biggest shortcoming though is that it doesn't support different interpreters per project a la virtualenv so you end up switching between the osx terminal and Komodo, and using it as a glorified text editor rather than an IDE. I was hoping that would be resolved in the newly released version 6 but alas no.
Since I mostly use it to do Django work, I flirted with Pycharm which does support virtualenv & Django but I just don't seem to enjoy Java based IDE's, so sorry Jetbrains, nothing personal, but it's not for me. I'll also be curious to try Xcode 4 when it releases to see how it shapes up for pythonistas, but for now it's Komodo or commandline (ipython/bpython etc).
Disappointment however is the mother of invention, and I belatedly worked out that actually you can use virtualenv with Komodo, just not the way you expect. Here's the trick if you haven't already worked it out:


ln -sf $VIRTUAL_ENV/bin/python /Users/$USER/bin/python cd $VIRTUAL_ENV/project
This ensures the virtual python we're working on it is always the first python to be found on the path when Komodo launches, and then it changes into the directory I want to be in the pythonpath.
You can then edit your virtualenvwrapper's postactivate script for the project in env's bin directory, so that it sets the Django settings modules and launches Komodo IDE when you run workon [your_env] from the terminal.
export DJANGO_SETTINGS_MODULE=your_project.settings /Applications/Komodo\ IDE.app/Contents/MacOS/komodo-bin &>/dev/null &
Now any python interpreter's you start in Komodo have your Django settings ready to go and will use the correct python binary, and site-packages.
Simple huh? Wish I'd realised that a year ago...
Anyway, Komodo 6 looks pretty solid, and using the preferences can drop down to a pretty minimalist interface which I like. I look forward to digging around the improvements in the new version, and if you're not wedded to a particular python IDE you might want to give Komodo 6 IDE a whirl.
4 comments:
- Doug Hellmann said...
-
That's pretty nice. You should package it up as a plugin, like I did with virtualenvwrapper-emacs-desktop (http://www.doughellmann.com/projects/virtualenvwrapper-emacs-desktop/).
- 8 November 2010 11:02 AM
- Daniel Apolinario said...
-
I use virtualenv differently. Working with and he uses Pinax virtualenv.
What I did was change the import directory in the project. Also create some functions in the toolbox to use python Pinax (which is in virtualenv).
In my toolbox I have a folder to work only with pure Django and another folder to work with Pinax. - 9 November 2010 6:01 AM
- Brett said...
-
@doug thanks for the suggestion (and virtualenvwrapper!). I'm not sure in itself it would add much value, or maybe I'm not seeing it clearly.
People like to install their project, working directory, and envs in all sorts of places, and also set their django settings to different contexts.
If I'm pre-defining their layout and settings then I'm moving down the buildout path of one "correct" way. Not sure if that works.
It would be so much simpler if Komodo/other editors just allowed environment variables per project, though I appreciate that is easier said than done.
What I would like to see though is a one step install packages in new environment or even the reverse, make new env and install:
pip install -c
mkvirtualenv --install or -r - 10 November 2010 1:15 PM
- Eric Promislow said...
-
Version 7 of Komodo supports some project-specific preferences, notably Python projects. The environment settings are still global only.
- Eric - 23 November 2011 6:19 AM
No comments:
Post a Comment