question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jedi is "smart enough to figure out which Virtual environment you're currently using"?

See original GitHub issue

The 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:

  1. If this is the best/intended way, it would help if jedi-language-server documented this
  2. 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
gwerbincommented, Oct 26, 2022

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

0reactions
gwerbincommented, Aug 26, 2022

@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”?

Read more comments on GitHub >

github_iconTop Results From Across the Web

jedi-language-server/README.md at main - GitHub
Don't worry, jedi is smart enough to figure out which Virtual environment you're currently using! Capabilities. jedi-language-server aims to support Jedi's ...
Read more >
how can I find out which python virtual environment I am using?
You can use sys.prefix to determine which virtualenv you're in. import sys print(sys.prefix). from the sys docs.
Read more >
Using Python Environments in Visual Studio Code
Using Python environments in VS Code. This article discusses the helpful Python environments features available in Visual Studio Code. An "environment" in ...
Read more >
Python Virtual Environments: A Primer
In this tutorial, you'll learn how to work with Python's venv module to create and manage separate virtual environments for your Python ...
Read more >
Virtual environments for absolute beginners — what is it and ...
Once you have a virtual environment, you can tell it to create a list for you of all of the packages it contains....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found