0
M-x pyvenv-activate <RET>
~/Documents/bitbucket-python-scripts/.env353 <RET>

works fine. Elpy Config buffer confirms that.

However with the following in ~/.emacs file

(require 'package)
(add-to-list 'package-archives
             '("melpa-stable" . "https://stable.melpa.org/packages/"))
(package-initialize)
(advice-add 'python-mode :before 'elpy-enable)
(elpy-enable)
(custom-set-variables
 '(elpy-rpc-python-command "python3")
 '(python-shell-interpreter "python3")
 '(pyvenv-activate "~/Documents/bitbucket-python-scripts/.env353"))

when I start Emacs and

M-x elpy-config

I see in the Elpy Config buffer that the virtual environment is not set. custom-set-variables were generated by Customization option of Emacs

Please point out my error.

Using: Elpy 1.28.1 Emacs 24.5.1 Debian GNU/Linux 9.8 (stretch)

UPDATED

(pyvenv-activate "~/Documents/bitbucket-python-scripts/.env353")

In ~/.emacs just after (elpy-enable) properly activate the virtual environment .env353. I have no idea why custom-set-variable command (obtained through customization) doesn't work.

4
  • Immediately I notice that custom-set-variables sets variables whereas pyvenv-activate is a function. If you check C-h v, my guess is that you now have a variable called pyvenv-activate whose value is the given path. The elpy-rpc-python-command and python-shell-interpreter should be okay, as those are indeed variables. Try breaking out the pyvenv-activate statement and see how that works. Apr 29, 2019 at 12:22
  • (pyvenv-activate ...) works fine. I was following the recommendations from github.com/jorgenschaefer/elpy/wiki/Configuration. They advised to use Elpy Config buffer and customization within. Apr 29, 2019 at 13:21
  • Hmm, it is somewhat confusing that there is a pyvenv-activate variable and function. I notice that the documentation for the variable states, "This is rarely useful to set globally", whatever that implies. It seems that the pyvenv-activate variable only holds the path to the venv. It doesn't activate it. The function call is what activates it and that's not being called after you assign the pyvenv-activate variable. Apr 29, 2019 at 13:48
  • pyvenv needs to know the execution path for python, so add that path in your init file. Depends on operating system.
    – Ian
    Apr 29, 2019 at 14:35

0

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.

Browse other questions tagged or ask your own question.