简体   繁体   中英

Specifying python interpreter from virtualenv in emacs

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 Mx py-shell , I get ~/local/bin/python so if I try to Mx 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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM