Jedi is "smart enough to figure out which Virtual environment you're currently using"?
See original GitHub issueThe README:
Alternatively (and preferably), use pipx to keep jedi-language-server and its dependencies isolated from your other Python dependencies. Don’t worry, jedi is smart enough to figure out which Virtual environment you’re currently using!
I’m sold on using pipx, but as far as I can see Jedi isn’t and can’t be smart enough to figure out which virtual environment to use, at least not without some help. If I use jedi-language-server on a folder, there is no way for Jedi to know which virtualenv to use - in fact I might have multiple venvs I’m using for that folder. I’ve attempted this using lsp-jedi for Emacs, and “jump to definition” fails to work if the item comes from a dependency located in a venv (e.g in ~/.virtualenvs/myproject
).
Some clients may be configured with some mechanism for linking projects to venv, but I don’t think Jedi can do it by itself.
After browsing the source code of jedi-language-server, I have found just one way to get it to work without changing the source - by creating .jedi/project.json
in the project root as follows:
{
"environment_path": "/home/me/.virtualenvs/myproject"
}
This is an almost undocumented feature of Jedi it seems - it fact it is wrongly documented as being .jedi/config.json
.
I’m not sure how this is supposed to work, so:
- If this is the best/intended way, it would help if jedi-language-server documented this
- It would help if there was another way - specifically a config option that could be passed from the client. I don’t think any of the existing configuration options cover this. This would enable clients to pass it using editor-appropriate settings mechanisms
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9 (8 by maintainers)
For anyone watching this issue:
My PR #232 adding this feature just merged! And the latest Jedi Language Server release 0.38.0 should finally make this explicitly configurable using the initialization option
workspace.environmentPath
.For any Neovim users, here is how I set it up in my config, with some helper functions to automatically detect the root dir, environment, and extra source paths: https://git.sr.ht/~wintershadows/dotfiles/tree/eafeb864/item/.config/nvim/lua/plugin-config/nvim-lspconfig.lua#L544-770
@pappasam I should have also mentioned that I installed
jedi-language-server
with Pipx and use that version everywhere. I’d prefer to not install it separately in each env if I can avoid it!Or have I misunderstood how Jedi LS works? Can it detect libraries from “python B” while itself running under “python A”?