Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pyright): use activated virtual environment if possible #3557

Closed
wants to merge 1 commit into from

Conversation

laddertosky
Copy link

Problem:
Pyright will use system python by default, even if we already have a virtual environment activated.

Solution:
Check current if VIRTUAL_ENV exists in environment variable, if so, set the default pythonPath with the binary inside.

Problem:
Pyright will use system python by default, even if we already have a
virtual environment activated.

Solution:
Check current if VIRTUAL_ENV exists in environment variable, if so, set
the default pythonPath with the binary inside.
@laddertosky laddertosky marked this pull request as ready for review January 13, 2025 07:09
@laddertosky laddertosky requested a review from glepnir as a code owner January 13, 2025 07:09
@lithammer
Copy link
Collaborator

I can't reproduce this. Works fine for me? What version of pyright?

@@ -40,6 +40,21 @@ local function set_python_path(path)
end
end

local python_bin = function(venv)
if vim.fn.has('win32') == 1 then
return venv .. '\\Scripts\\python.exe'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return venv .. '\\Scripts\\python.exe'
return venv .. '/Scripts/python.exe'

@laddertosky
Copy link
Author

I figure out my mistake, sorry for taking your time to check. The problem is I have two different virtual environments in two projects and I forgot to switch when I navigate to the second one.

@justinmk
Copy link
Member

I can't reproduce this. Works fine for me? What version of pyright?

Yeah, if the venv is "activated" then $PATH would have been modified, so searching for python should already work.

@justinmk justinmk closed this Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants