3

Full disclosure: I installed anaconda and set it to the path variable. After I did this I was able to access elpy-config which I was not able to (see my prior question). I still pretty much have no idea why this worked and what I'm doing right or wrong.

My three questions:

1. When I type command M-x pyvenv I get a message saying Can't find a workon home directory, set $WORKON_HOME. How do I actually do this without screwing up the existing paths?

2. How do I setup a virtual environment? I have trouble understanding this conceptually and I get confused as to what I'm actually doing when following instructions.

3. I read that having pip and conda simultaneously can bring issues when trying to install various packages. The warning tells me that I need pip...but do I?

Elpy Configuration 

Emacs.............: 26.3
Elpy..............: 1.34.0
Virtualenv........: None
Interactive Python: python . (c:/Users/Robby Parliament/AppData/Local/Microsoft/WindowsApps/python.exe)
RPC virtualenv....: rpc-venv (c:/Users/Robby Parliament/.emacs.d/elpy/rpc-venv)
 Python...........: c:/ProgramData/Anaconda3/pythonw.exe 3.8.3 (c:/ProgramData/Anaconda3/pythonw.exe)
 Jedi.............: 0.17.1
 Rope.............: 0.17.0
 Autopep8.........: 1.5.3
 Yapf.............: 0.30.0
 Black............: Not found
Syntax checker....: flake8.exe (c:/ProgramData/Anaconda3/Scripts/flake8.exe)```

Followed by:

Warnings

You have not activated a virtual env. While Elpy supports this, it is
often a good idea to work inside a virtual env. You can use M-x
pyvenv-activate or M-x pyvenv-workon to activate a virtual env.

Elpy could not connect to Pypi (or at least not quickly enough) and
check if the python packages were up-to-date. You can still try to
update all of them:

[Update python packages]

Pip doesn't seem to be installed in the dedicated virtualenv created
by Elpy (c:/Users/Robby Parliament/.emacs.d/elpy/rpc-venv). This may
prevent some features from working properly (completion,
documentation, reformatting, ...). You can try reinstalling the
virtualenv. If the problem persists, please report on Elpy's github
page.

[Reinstall RPC virtualenv]

The black package is not available. Commands using this will not work.

1 Answer 1

3

Step 1: If you haven't already done so, go ahead and create a new conda environment. Let us say we want to create an anaconda environment with name py38 which uses python 3.8. Execute the following in an (Anaconda prompt)

conda create --name py38 python=3.8

Note: You can get to an anaconda prompt by clicking on the windows button and then searching for anaconda prompt

Now we need to find out where the previous conda create command created your virtual environment. In the anaconda prompt execute:

conda info --envs

This command will show you a list of locations where your virtual environments are located. (including the base environment that anaconda creates by default). The output will look something like the following:

# conda environments:
#
base                  *  C:\ProgramData\Anaconda3
py38                     C:\Users\robbie\.conda\envs\py37

Now everytime you create a virtual environment it will (by default) go inside of C:\Users\robbie\.conda\envs unless you tell it otherwise by messing with config files. Since you are getting started I suggest you go with the default location.

Step 2 We can now set the WORKON_HOME to be this location. Put the following in your init.el (obviously change it to the actual output you got previously)

;; workon home
(setenv "WORKON_HOME" "C:/Users/robbie/.conda/envs/")

Now re-start emacs and run

M-x: pyvenv-workon [TAB]

Your previously created virtual environment will now show up here. Choose your desired virtual environment (in this case py38) now your Emacs session uses this virtual environment. If you now run elpy-config you will see that the python entry in your elpy configuration has changed to something like:

Python...........: python 3.8.1 (c:/Users/robbie/.conda/envs/py38/python.exe)

If you'd rather use the base anaconda.

M-x: pyvenv-activate [RET]

then give the location of your base environment. In your case c:/ProgramData/Anaconda3. I suggest you heed elpy's advise here and always work inside a virtual environment.

As for your third question conda and pip can co-exist peacefully. If you want more information see this blogpost by Jake VanderPlas.

Notes:

  1. You can get more information about (for example) conda create by running in the anaconda prompt.
conda create --help
  1. In windows you must run these commands in the anaconda prompt rather than your regular windows cmd prompt.
1
  • Hi - so first off thank you for your response. Secondly, it appears to me that I have a more fundamental issue with emacs that I must resolve before further tinkering with virtual environments. I'm going to post a new question I'd love if you could take a look
    – katsoop
    Aug 6, 2020 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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