views:

238

answers:

1

Today I've been trying to bring more of the python related modes into my emacs configuration but I haven't had much luck.

First what I've noticed is that depending on how emacs is launched(terminal vs from the desktop), the interpreter it decides to use is different.

  • launched from kde menu: M-! which python --> /usr/bin/python

  • launched from terminal: M-! which python -->~/local/bin/python

I can kind of accept this since I have my .bashrc appending ~/local/bin to the path and I guess kde ignores that by default.I can work around this, however what I don't understand is then if I activate a virtualenv, I would expect M-! which python to point to ~/project.env/bin/python however it still points to ~/local/bin/python

Thus when I M-x py-shell, I get ~/local/bin/python so if I try to py-execute-buffer on a module that resides in a package in the virtualenv, py-shell will complain about not knowing about modules also in the virtualenv.

Setting py-python-command to ~/project.env/bin/python seems to have no effect after everything is loaded.

So I guess the overall crux of my question is, how does one get all the python related emacs stuff pointing at the right interpreter?

+2  A: 

So it seems that python-shell does the right thing by picking up the environment settings, whereas py-shell does not. python-shell is provided by python.el and py-shell is provided by python-mode.el , There's bug reports etc related to this, so I'm just not going to use py-shell for now. Figured I'd close the loop on this in case the google machine considers this a high ranking item for one reason or another.

Tom Willis
A useful page on using virtualenv with Emacs (since I found this page via Google): http://jesselegg.com/archives/2010/03/14/emacs-python-programmers-2-virtualenv-ipython-daemon-mode/
Nicholas Riley