How can I configure Elpy to use dev dependencies like Black, Jedi, and flake8 that are installed in a Poetry project virtual environment rather than those that are installed systemwide?
Setting up Emacs Elpy with Poetry
2.5k views Asked by jidicula At
2
There are 2 answers
0
On
If you use emacs -nw, then another option is
- Install virtualenvwrapper in poetry project. That is run
poetry add -D virtualenvwrapper. - Install elpy dependencies you need.
M-x elpy-config' to find dependencies. Sopoetry add -D jedi rope autopep8 yapf black flake8`. This can also be done when elpy prompts you, but then it will probably install as a normal dependency and not just dev dependency. - Add
(setq elpy-rpc-virtualenv-path 'current)so that elpy uses the poetry virtual env for Virtualenv, Interactive Python, RPC virtual env. - Launch emacs through poetry
poetry run emacs -nw
You need to do this for each poetry project. There should be way to install some of these globally in pyenv and have poetry and the project virtual env pick it up. However, doing it for each project keeps dependencies isolated, even for dev stuff.
Use the
poetry.elEmacs package withpoetry-tracking-modeenabled byadd-hooking it toelpy-mode-hook. Elpy will automatically detect the Poetry virtual environment and check for those dev tools in that environment.Jan 2021 update: I've since stopped using Elpy and switched to
lsp-modeandlsp-python-ms- it's a far better development experience. The only caveat is that it can only discover virtualenvs local to the project, so Poetry has to be configured to create venvs locally (poetry config virtualenvs.in-project true).