elpy icon indicating copy to clipboard operation
elpy copied to clipboard

[Question] How to work with `direnv`?

Open failable opened this issue 3 years ago • 2 comments

Currently Elpy can not work with direnv (https://github.com/wbolster/emacs-direnv / https://github.com/purcell/envrc), is there a way to make Elpy recognize VIRTUAL_ENV set by direnv? Thanks.

failable avatar Jun 28 '22 06:06 failable

After you allow direnv in the project directory, the virtualenv will automatically become activated when you enter it. You can tell elpy to use the currently activated virtual environment with:

(setq elpy-rpc-virtualenv-path 'current)

You must launch emacs from somewhere in the direnv enabled root for this solution to work. Otherwise, consider setting elpy-rpc-virtualenv-path dynamically with the options that it supports: https://elpy.readthedocs.io/en/latest/concepts.html#option-elpy-rpc-virtualenv-path

skullgoblet1089 avatar Jul 24 '22 12:07 skullgoblet1089

Here is an example of how you could start to connect direnv with elpy dynamically via virtualenvwrapper

  • Format the .envrc file layout to use $WORKON_HOME: https://github.com/direnv/direnv/wiki/Python#virtualenvwrapper
  • Enter the directory, allow direnv, activate or workon the virtualenv and install project dependencies etc.
  • Open emacs from wherever you like, and interactively call pyvenv-workon from elpy mode to configure elpy to use the project virtualenv you setup previously as managed by virtualenvwrapper

Reference

  • https://virtualenvwrapper.readthedocs.io/en/latest/

skullgoblet1089 avatar Jul 25 '22 14:07 skullgoblet1089