Python / Emacs setup

When I got a new computer a few days ago, I installed the latest version of Emacs, 24.2, and broke my Python environment. I decided to re-evaluate my environment and start over. I asked a question on the Python Google+ group and here’s a summary of the Emacs packages recommended.

  • python-mode
  • rainbow-mode, rainbow-delimiters-mode
  • flymake-mode (hooked up to flymake-pyflakes)
  • linum-on
  • jedi
  • pycheckers + pyflakes
  • rope
  • electric-pair
  • show-paren
  • auto-complete
  • yassnippets

What recommendations do you have for packages? Links to relevant articles?

It might be better to leave your comments on Google+ rather than here so the answers will be in one place.

15 thoughts on “Python / Emacs setup

  1. ein (emacs client for ipython notebook) looks good if you can get it to work. It didn’t work when I tried a few months ago but I think the underlying bug (in the elisp websocket library) is fixed now.

  2. @Mark
    no, rope provides (advanced) refactoring, when jedi is “limited” to autocompletion and documentation. However (I’m a vim user, but it shouldn’t matter here) since I started using jedi, I find myself using rope less and less…

  3. python-mode
    You cannot do it without this one.

    rainbow-mode, rainbow-delimiters-mode
    python-mode has already some colors for keywords, strings, etc, etc. I don’t really like rainbow mode because there too many colors on the screen.

    linum-on
    I have this one by default set to off but some time I switch it to on if I need line numbers.

    rope
    Is one is convenient when you do code refactoring. In my environment it is off by default and I turn it on when needed.

    electric-pair – show-paren
    I use both of them. I am so used to both of them that I couldn’t do without them.

    auto-complete – Jedi
    I am not a fan of pulldown menus constantly flashing on my screen. I found that distracting.

    yassnippets
    This one is great. I have extended the macros for python and I use it a lot.

  4. I am a huge fan of vimpulse, which gives emacs vim-like key bindings, including visual mode. Having used standard emacs for 6-8 years before going with viper/vimpulse, my experience is that vi key bindings are richer and more concise than the stock emacs bindings, although they are probably harder to learn.

    Using VIM itself was a non-starter for a number of reasons, mainly lack of syntactic analysis (i.e. auto indent) and a good extension language.

    I’ve also found that I prefer the command/insert mode stuff versus having to perpetually keep my little finger on the control key. Even after mapping it to caps lock, which I would highly recommend.

    I haven’t invested too much in Python+emacs beyond stuff that would apply equally to Python+C++. Jedi looks very interesting though. I might give that a whirl sometime.

    I have my own snippet tool: https://github.com/kungfucraig/devtools

  5. Greg: I don’t know whether I’d use Emacs if all I did was edit Python. There are some good Python IDEs. But the main thing I like about Emacs is using it for multiple tasks.

    At one point I was using a different application for editing each language: one for HTML, one for C++, one for Python, etc. and I wasn’t very good at using any of them. I picked Emacs back up to have one editor for everything and so that hopefully I could learn to use it well. For me, the occasional difficulties with Emacs are outweighed by the benefits.

    Everyone: Thanks for the suggestions.

  6. @Soli
    Right, of course. I only played with rope briefly; from memory I had issues getting to work consistently and it was slow (actually, I think it was trying to index my entire python library, and maybe even hitting errors or infinite loops… it was quite a while ago). Jedi does look very promising for what I’d mainly want it for though. I should probably give both a shot again.

  7. “python-mode” is ambiguous:
    * Emacs has always† shipped the file “python.el” which implements a major mode called “python-mode”.
    * Python folk released their own file, not shipped with Emacs, called “python-mode.el”. Emacs couldn’t ship it due to copyright reasons.
    * Fabián Ezequiel Gallina wrote, from scratch, a version of python.el that merged the best‡ features of python.el and python-mode.el. This is the version shipping with Emacs since 24.1.

    In conclusion: Use the python-mode shipped with Emacs. If you’re using an Emacs older than 24.1, upgrade!

    Setting up rope with Emacs is so complicated I wouldn’t bother. I spent a whole weekend trying and failed. You need rope (a python refactoring library), pymacs (a system that allows people to write Emacs extensions in python, though I may be misrepresenting/misunderstanding it here), ropemode, and ropemacs. Some of these include both python and elisp components, but lack decent packages, so forget about installing using your existing system, python, or Emacs package managers (the elisp component installed with the Emacs package manager will be out of sync with the python component installed from PyPI). You’ll have to build them from source.

    Jedi looks promising, and much simpler. But I haven’t tried it yet.

    † Since 2005
    ‡ I don’t know the details

  8. David: Thanks for clarifying the python-mode history. Given your experience and Mark’s with rope, I think I’ll pass. When I read “I spent a whole weekend trying,” that was enough for me. :)

    This article from Mastering Emacs describes rope as “disappointing, slow, crash-prone, obtuse and impossible to extend. ” But the article speaks highly of Jedi.

  9. I didn’t know fgallina’s work was already shipping; that’s great news. It’s under active development independently though, so you may still wish to look into it.

  10. Vim Toutenhoofd

    Within a month or two I hope to take up programming again, after not having done that for many years. I intend to write Python, using Emacs. I’m entering this comment here so I can then also check the box labeled “Notify me of followup comments …”

Comments are closed.