GNU Emacs Packages for Python Programming

Lately I’ve been writing a lot of Python code, so tonight I want to talk a little about the GNU Emacs packages I use for Python programming.

Catching Syntax Errors and More

Flycheck is an amazingly useful package for finding programming errors in real-time, and it supports a number of languages right out of the box, including Python. It saves time to be able to see that I’ve made a syntax error or something while writing the code instead of finding out later when I actually run that code.

There are a lot of third-party extensions for Flycheck out there, adding or improving support for different languages. I recommend the following for Python:

  1. flycheck-pyflakes

  2. flycheck-mypy: Recently I wrote about static type-checking in Python using Mypy. This package allows Flycheck to use Mypy to catch type-errors in my code as I write it. It’s not useful for all projects, e.g. anything using Python 2 which Mypy doesn’t support, but when available I’ve found it to be an invaluable tool.

Live Coding

Live-py-mode is a package for Emacs (and Eclipse) which lets you see the results of your Python code in another window as you write it. Effectively it’s like Python running as an "inferior process" while automatically sending all of my code to it, instead of having to use some of Python Mode’s built-in commands like python-shell-send-region.

I recommend watching this video to see just what you can do with live-py-mode.


I’m a fan of Helm, so I use helm-pydoc for quickly looking up documentation on Python modules and libraries. The package can do more than simply bring up documentation though. As you’ll see it also lets me open up the source code for packages or import them into the current buffer using either the import ... or from ... import ... syntax if I want.

Running Tests

The pytest.el package provides a collection of useful commands for running pytest, which I use on most Python projects. If you use Hydra for managing key-bindings then you may find my personal Hydra for pytest.el to be useful:

(define-key python-mode-map (kbd "C-c C-y")
  (defhydra hydra-pytest (:color blue)
    ("a" pytest-all "all")
    ("m" pytest-module "module")
    ("o" pytest-one "one")
    ("d" pytest-directory "directory")))

The Big One

Anaconda is a package which adds a lot of functionality for Python programming. To quote the project page, its features include:

  • context-sensitive code completion
  • jump to definitions
  • find references
  • view documentation
  • virtual environment
  • eldoc mode

If you want a big chunk of additional Python programming features in a single package then you can probably do no better than to use Anaconda. (Edit: I forgot about Elpy, see the comments below.) And if you use Company for auto-completion, which I personally do, then you will also want the Anaconda backend for Company.


6 thoughts on “GNU Emacs Packages for Python Programming

    1. I’ve downloaded it but never configured, set it up, etc. However, I have heard really good things about Elpy from people whose opinions I have a lot of confidence in. So even though I haven’t used it myself, I still feel comfortable recommending it.

    1. When I need to work with code remotely in Emacs I use its built-in Tramp functionality. However, I haven’t yet tried that with Python (not since around 2008 anyway), so I can’t speak to how well it works together with the packages mentioned above. I do expect to be working more heavily with remote Python coding, especially using virtualenv and docker, in the near future. So I will make it a note to come back and write about this topic again once I have some experience with that, what works well, what doesn’t, etc.

  1. obviously like your web site but you need to
    test the spelling on several of your posts. Many of them are rife
    with spelling issues and I in finding it very troublesome to tell the truth on the
    other hand I’ll certainly come back again.

Add Your Thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s