21

What is the best way to use conda environmets using emacs as a Python IDE?

I have got different conda environments while programming in Python:

$ conda info -e
# conda environments:
#
django                   /Users/Pablo/anaconda/envs/django
scipy                 *  /Users/Pablo/anaconda/envs/scipy
visual                   /Users/Pablo/anaconda/envs/visual
ml                       /Users/Pablo/anaconda/envs/ml
root                     /Users/Pablo/anaconda

But when I use crtl+c crtl+c emacs only uses my the Mac OS X default Python PATH. How can I chage it between all the different conda environments?

20

I'd suggest using pyvenv library, it provides a neat interface to selecting a virtual env among several alternatives updating interpreter and library paths. You will need to alter WORKON_HOME variable (it defaults to $HOME/.virtualenvs used by virtualenvwrapper).

(setenv "WORKON_HOME" "/Users/Pablo/anaconda/envs")
(pyvenv-mode 1)

After that choose the environment with M-x pyvenv-workon.

| improve this answer | |
  • It worked for me, thank you! Do you know where can I found more documentation on this matter? I haven't found any information about pyvenv and anaconda, but I added this two lines in my settings file and it's working fine. @immerrr – PabloRdrRbl Feb 5 '16 at 22:55
  • On which matter? On writing configs or on pyvenv itself? – immerrr Feb 6 '16 at 22:46
  • 1
    To switch between python3 and python2, I had to issue (setq python-shell-interpreter "python3") or (setq python-shell-interpreter "python2") – Lorem Ipsum Jun 20 '18 at 23:30
  • A bit more robust way of doing this is (setenv "WORKON_HOME" (concat (getenv "CONDA_PREFIX") "/envs")). This way when you change machines but want to keep your emacs config file consistent. – D_Serg Mar 31 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.