Python and Emacs

Good info:

Look at pymacs too:

There are lots of "Emacs as Python IDE" articles. This one is mine, and it's geared towards Emacs 24.

Try to re-create what's possible in Eclipse. Mostly I use the following features in Eclipse:

Note that "generation of getters and setters" isn't really useful in Python. I'm not sure how feasible "auto fix of errors" is in emacs.

In a nutshell, use Rope. It's a python refactoring library. Very useful blog entry here:

Basically, install pymacs, rope, and ropemacs. You get:

A note about the code-completion in rope: it works via the minibuffer. There's an emacs package called AutoComplete that works via a popup GUI. You can configure it so that it uses rope. Good blog entry here:

For unit tests, see this website:

I've been using Debian derivatives for a while now (first Debian, then Linux Mint Debian Edition, then standard Linux Mint) and although I'm usually one to use the distributions packages when possible, in this case I found it better to use the most up to date packages I could. Bugs are fixed in the latest version that make them difficult to use with the latest emacs.

Install Pymacs

This is an interface between emacs and python, allowing you to write emacs extensions in python. There are two pieces, and emacs piece and a python piece.

The emacs piece is easy to install. If you have the package system set-up like this:

(when (>= emacs-major-version 24)
  (require 'package)
  (add-to-list 'package-archives
               '("elpa" . ""))
  (add-to-list 'package-archives 
               '("marmalade" .  ""))
  (add-to-list 'package-archives 
               '("melpa" . "") t)

Then you can just select Pymacs to install via the packages buffer. This will install the emacs part of Pymacs, but not the python part. To install the Python part, do this:

pip install -e "git+"
cd $VIRTUAL_ENV/src/pymacs

In my case I was installing as root, so I had to cd into /root/src/pymacs:

cd /root/src/pymacs

Then copy over to where the local python packages are kept:

cp /root/src/pymacs/ /usr/local/lib/python2.7/dist-packages


You can install virtualenv.el to get the ability to switch between virtualenvs within emacs. What this means exactly, I'm not 100% about. I think it means that you will be able to launch an inferior python process within emacs that will use the packages in your virtualenv.

Unfortunately, I do not think that ropemacs actually ends up using the virtualenv once you switch into it. I'm not sure why, but I suspect that the python process used by rope isn't the same one that's used for the Python inferior modes.

One possibility is to start your emacs process on the command line once you've activated your virtualenv. This is inconvenient if you use emacs for a bunch of other things and you already have an instance running before you start editing your python files.

Another possibility seems to be pasting this is in your .ropeproject/ folder:

VIRTUAL_ENV = "/home/user/envs/envname/"
execfile(ACTIVATE_FILE, dict(__file__=ACTIVATE_FILE))

This works, and it's very simple, though it seems a bit hackish to me.

Accessing the documentation

Maybe use rope?

You also do this via pylookup. Note that pylookup only appears to work on python 2.6 and above.

Good instructions here:

Basically, you download the package and put it somewhere in your emacs path, like ~/.emacs.d. You create the database index by running:

./ -u python-2.7.1-docs-html

The -u parameter can be a URL if you want to access the web for the documentation. Otherwise, point the command to a local copy of your documentation.

Try it out by running this:

./ -l ljust

In your .emacs file, put this:

(autoload 'pylookup-lookup "pylookup")
(autoload 'pylookup-update "pylookup")
(setq pylookup-program "~/.emacs.d/pylookup/")
(setq pylookup-db-file "~/.emacs.d/pylookup/pylookup.db")
(global-set-key "\C-ch" 'pylookup-lookup)

Code completion

Rope is a popular way to go here. It's non-emacs specific.

Ropemacs integrates rope into emacs. You can also hook AutoComplete into Rope (for pull down completion menus)


PythonAndEmacs (last edited 2015-07-18 02:44:59 by DesmondRivet)