Python Development In A VM Using Emacs And Virtualenv
, Wellesley, MAPyCharm recently added some excellent configuration options to facilitate using a remote Python interpreter. With them you can run PyCharm on a host machine, and execute everything on a guest VM. You can keep a single copy of the code and a virtualenv, shared between the host and guest, and tell PyCharm how to map the local and remote filesystem paths to each other. PyCharm will even do code completion without having a second copy of the code or virtualenv on the host machine. Beautiful!
I searched for something similar in Emacs, and I found a couple of interesting leads[1][2], but complete solution that’s exactly what I want. I prototyped two approaches:
- Shared filesystems, with a mapping between guest and host.
- TRAMP, referencing the code over SSH using TRAMP.
The former is pretty raw and incomplete. The latter is more promising in the near term. It consists of:
-
python.el
- a replacement for thepython.el
distributed with Emacs 24 that makes its python-send-region TRAMP-aware. -
demo.py
- an interactive demo. -
bootstrap-virtualenv.sh
- a Bash script to bootstrap a virtualenv for use via Emacs over TRAMP. -
python.sh
- a Bash script to run python in a virtualenv. -
.dir.locals.el
- configuration for Emacs to run python via the Bash script wrapper. -
tramp-dir-locals.el
- a hack to make directory local variables work in directories opened via TRAMP.
If you’re doing anything similar, I’d love to know how.
Update: 2012-06-06: Michael Albinus started improving the upstream code on the Emacs trunk today!