3

How would I activate a specific virtual environment in my init file? I know how to activate it manually, but I don't like to do it every time I start emacs.

To activate it manually I used:

pyvenv-activate

Then a path needs to be specified and it works. So I tried the following in the init file:

(pyvenv-activate PATH_TO_VENV)

Unfortunately it tells me:

Invalid function: (quote pyvenv-activate)

I want to do this, because without activating the venv, elpy does not find it and thus doesn't find jedi etc.

1 Answer 1

2

Load pyvenv first and then activate env. Add this to your init file.

(require 'pyvenv)
(pyvenv-activate "~/.virtualenvs/exp/")

If you are using virtualenvwrapper, you can use pyvenv-workon

(require 'pyvenv)
(pyvenv-workon "exp")

If you load elpy first, it will automatically load pyvenv. You don't need to do (require 'pyvenv).

3
  • Does it load pyvenv twice, if I still add the require statement, or does it realize, that the dependency is already fulfilled? I tend to keep the require, just in case I move it around in my init file some day… Commented Nov 14, 2015 at 10:36
  • 1
    require checks before loading features. So it should load only once. Commented Nov 14, 2015 at 11:29
  • How could I verify that pyvenv is successfully loaded venv?
    – alper
    Commented Jun 20, 2021 at 21:24

Your Answer

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

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