Setting up Emacs for Python development

I've started tinkering with Emacs again!  Some cool add-ons which have gotten me excited about Emacs again:

Some commands


Alternative editors

  • spyder (scientific dev environment)

Update 2nd July 2012

I've gone back to using PyDev (an Eclipse plug-in) for my Python development.  I do enjoy Emacs but PyDev is simply too pleasurable and powerful to ignore.  Plus PyDev appears to be receiving increasing amounts of development effort, in contrast to some of the Emacs tools I experimented with.   And Eclipse offers enough configuration options to mean that I can get Eclipse to feel pretty "Emacs-like".  The notes below are only about two thirds complete but they might still be useful...


So, I've settled on using Python 2.7 for the development of my disaggregation system.  I'm very happy with Python so far.  The more I learn about Python, the more excited I get; which is the oposite to the situation I experienced with MATLAB: the more I learnt about MATLAB, the more repulsed I became.

So, the next question becomes: which IDE to develop in?  I spent a few days using the Eclipse plugin PyDev but several things started to bug me; notably the fact that the interactive console doesn't respect the correct Eclipse keybindings.  Plus Eclipse requires lots of messing about with the mouse which can slow you down a bit.  So I started thinking seriously about using my old friend Emacs to develop Python in.  Pedro produced an excellent blog post describing how to install a bunch of add-ons to Emacs to make it a powerful Python IDE.  Unfortunately things have changed a bit since 2010 when that blog post was produced.  Hence this blog post is a list of modifications to Pedro's blog post to bring it up to date.  I certainly don't intend to replicate Pedro's excellent work; I'm just producing a "diff" to bring his blog post up to date. There's also some good notes on vanguard33's blog.

  1. Install iPython
  2. Install python-mode into ~/.emacs.d/ as per the instructions in the README and INSTALL files
  3. Don't bother manually putting (setq py-shell-name "ipython") into your ~/.emacs file. Instead, in emacs, type M-x customize-variable py-shell-name and change it to ipython
  4. easy_install rope ropemacs. Modify .emacs to get ropemacs to work as described in the ropemacs readme. Install Pymacs (there's a bug in the install at the time of writing; to get the install to work follow the step described in the bug report fix install of Pymacs on Python 2.7 (issue #28)). You might also need to add (setq py-load-pymacs-p 'nil) to your .emacs
  5. Magit is now hosted on github.

Useful resources

Tools I tinkered with but am not using

emacs-for-python looks like a quick and easy way to install lots of useful stuff. But I decided to install individual packages.

ipython.el:  I'm not certain if ipython.el is required or not (the latest version can be found in the ipython repository on github). There's lots of discussion about ipython.el on StackOverflow and github. There's also some discussion in the ipython editors.txt file (which I need to read). this recent comment by Andreas Röhler suggests that ipython.el should no longer be necessary. My assumption for the time being is that ipython.el is not required.

Autocompletion

The anything project has been superceded by the helm project. You can get the files using something like cd ~/.emacs.d; git clone git://github.com/emacs-helm/helm.git and then read the README.md file. There is also a helm-ipython project. HOWEVER, helm-python requires ipython.el (I submitted a bug report); and I'm fairly sure that ipython.el is now redundant.

auto-complete works pretty well. I grabbed the latest auto-complete from github. Before installing, it's necessary to also grab popul-el and fuzzy-el and put these two files in the auto-complete directory prior to installing. (It looks like the author has split fuzzy-el and popup-el from auto-complete but hasn't updated the documentation yet.) I like autocomplete to only offer help when I explicitly ask for help so I added (ac-set-trigger-key "TAB") (setq ac-auto-start nil) to my .emacs

Add new comment