Reputation: 5303
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 gives /usr/bin/python
launched from terminal: M-! which python gives ~/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 M-x 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?
Upvotes: 12
Views: 7545
Reputation: 26312
There is a virtualenv mode for Emacs. It requires Emacs 23.1 or higher.
This is a minor mode for setting the virtual environment for the Python shell using virtualenv and supports both python-mode.el and python.el.
Upvotes: 4
Reputation: 5303
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.
Upvotes: 8