Search code examples
emacspython-poetryelpy

Setting up Emacs Elpy with Poetry


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?


Solution

  • Use the poetry.el Emacs package with poetry-tracking-mode enabled by add-hooking it to elpy-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-mode and lsp-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).