-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Selected interpreter changes when the extension is starting up, when in DeprecatePythonPath
exp
#16291
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
Comments
To confirm, are you saying that it starts with the correct environment selected at the bottom left, then switches to the wrong one when you open a file, and that's what your screenshots are showing? Pylance uses the interpreter selected by the Python extension and doesn't go out to PATH. This sounds more like a Python extension interpreter selector bug than anything. |
it starts with the right venv one and soon as the language server starts you can see it picks up the wrong one from the path. soon as it gets this far
the toolbar updates and it's pointed to the wrong one. |
Thanks. I don't think this is a Pylance bug, then, but a bug in the Python extension to do with the interpreter selector. Pylance just queries for whichever interpreter is active and doesn't have the power to change it. I'll transfer this over to them; you will probably want to provide the logs in the Python output window as well, as that should provide some info as to what's going on here. |
@jakebailey, where can I track this transfer? will they reply here or are we talking a different project? thanks |
The issue has already been transferred, and the core extension team will handle this. |
Thanks for the bug report! We just wanted to quickly acknowledge we received it and we will triage this as soon as we can. |
@sgargan Please provide the logs as mentioned in the issue template. LogsOutput for
|
I do see that the Interpreter selected is not retained similar to #16291 when in deprecatePythonPath experiment. Can you add the following to your user settings and see if it helps,
|
@karrtikr the opt out worked for me, my venv python doesn't change, the test discovery works and I can run/debug tests again. Thanks for your help here. LMK if the logs are still useful to you and I'll add them. |
Great, thanks for confirming. |
DeprecatePythonPath
exp
Environment data
vscode
Expected behaviour
I expect vscode/python extension/pylance to respect the pythonPath from .vscode/settings.json and PYTHONPATH from .env when starting up the language server and running tools like the test discovery. Right now it ignores these and uses the python in the system path.
Actual behaviour
So I stumbled into this trying to get the test discovery working. Typically I work in a virtualenv for each project. I create a virtualenv in my project folder with the python3 module
I have source in a
src
folder, tests intests
and a requirements file installs pytest. Using the following runs my tests perfectly from the command lineTo use this venv in vscode I setup the following .settings file
and the .env folder to specify the PYTHONPATH looks like
When vscode first starts I see it is using my virtualenv path
Then soon as I click a python file e.g. a test file that kicks off the discovery, the language server boots and uses the first python it finds in the path, overriding my virtualenv one. See logs below
Of course this has none of my libraries installed and so the test discovery fails completely.
FWICT my vscode environment is setup correctly. if i prefix the ptyest discovery command with my PYTHONPATH and run it in a terminal, it discovers everything correctly. Not really sure why the
Logs
here are the pylance logs
The text was updated successfully, but these errors were encountered: