1

I've got code that needs python 2.7 (and other environments)

C:\Users\Me>conda info -e
# conda environments:
#
base                  *  C:\Program Files\Anaconda3
python2                  C:\Program Files\Anaconda3\envs\python2

I would like to be able to selectively activate python2 when I start a python shell in emacs (i.e. I send a line of code to the python interpreter using elpy). being able to put this in an init file would be cool.

I have tried both the conda and pyenv packages with no luck in my current configuration. Conda can't find my environments and pyenv doesn't seem to actually activate the virtual environment.

Using Emacs 26.1 and conda 4.5.11

Any help would be appreciated.

0

I use pyvenv to activate/manage my virtual environments and have the following called from my init.el...

(elpy-enable)
(pyvenv-activate "~/.virtualenvs/dskit")

I have installed virtualenvwrapper which resides in ~/.virtualenvs and creates the virtualenvs within there (e.g. dskit that is being activated). As you are using Conda change ~/.virtualenvs/dskit to point to the location of the Conda environment you wish to use. Obviously you then need to install the Emacs pyvenv package (I use the latest version from MELPA).

I'm by no means an expert in either Python, Virtual Envs or Emacs and used the following articles from realpython.com....

  • pyvenv is maintained by the author of elpy. Installing elpy will automatically install pyvenv as a dependency. A key component to elpy is elpy-config. It tells you what virtual environment is being used, if any. It tells you which Python executable is being used for RPCs (remote procedure calls). And finally, it let's you know what Python executable is being used for the interactive Python shell. Finding elpy-config was the "aha" moment for me. I highly recommend the pdf manual (I find it easier to read): media.readthedocs.org/pdf/elpy/latest/elpy.pdf – Lorem Ipsum Feb 6 at 14:18
0

Activate your virtualenv with:

(pyvenv-activate "C:\Program Files\Anaconda3\envs\python2")

If the binaries in your virtualenv are names "python2", you will need to set

(setq python-shell-interpreter "python2")

to ensure the good python binaries will be used by Elpy.

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.