I have the following in a .dir-locals.el

((python-mode . ((pyvenv-workon . "3.7")
     (projectile-project-compilation-cmd . "python -m unittest fixcompdb_test.py"))))

I use lsp-mode and the Pyls Python Language Server which is installed in the virtual environment labeled "3.7". I expect that when I open a Python file in the directory containing the .dir-locals.el, lsp-mode should be able to start Pyls. This doesn't work, lsp-mode reports that the Pyls server is not accessible. If I instead do "pyvenv-workon" and select "3.7" before opening a Python file it works, lsp-mode can start Pyls and I have a fully working lsp-mode session.

In the case when I do not explicitly do "pyvenv-workon" and lsp-mode is unable to start Pyls the virtual environment still works; all buffers in emacs use the correct virtual env and it is reported correctly in my doom-modeline.

It seems like lsp-mode is trying to start Pyls before Emacs has activated the virtual env. How do I set this up so that lsp-mode will try to start Pyls when the virtual env is up and running?

1 Answer 1


You just defined variable pyvenv-workon but not called this function. Take a look at this answer

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.