-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Pytest (and often other things) loaded with wrong PYTHONPATH #23920
Comments
Hi! To clarify is only testing using the wrong environment or the extension as a whole? We are aware of an issue of incorrect environment selection for testing but if this is for the extension overall then it would be related to something else and I can loop another coworker in. |
In my experience, it's probably everything taking the python path from the Python extension: Jupyter Notebooks, Terminal (I had to override the PYTHONPATH in terminal's env settings). When trying to debug what is wrong with the Jupyter Notebooks, I managed to narrow the issue to environmental variables delivered by the Python extension. Side note: today I surprisingly was able to use some features that a few days ago in a different project were broken. I still don't know if something was fixed (e.g. in the newest release), or in this particular project I just didn't have anything conflicting with the system packages. |
Ah gotcha- so were you able to adjust the environment variables or is it still causing issues? We have make many improvements in this area (environment selection and activation) and so hopefully that was the fix that helped with the previously broken package |
I will test it again and come back probably next week (I won't be able to do it today) |
Hey, I've checked again, and unfortunately, it still does not work. Sometimes I have luck that what I need does not conflict with the system packages, but generally - the wrong PYTHONPATH is still here, everywhere. |
FYI: I've just found a new workaround, let's configure Python extension to use
Then in the terminal you can observe:
And at least the Jupyter started to work. Not that in this case I used a local venv instead of the one from pyenv (I hope it's not the requirement, just a thing I needed). This is weird. |
I didn't intend to close the issue, it's a missclick - could you please reopen it? |
sorry for the delay- will investigate |
Type: Bug
Behaviour
Since a few weeks / months, I'm constantly falling into issues that VSCode is setting global python path instead of or before the current virtual env when invoking different extension features (tests from test explorer, Jupyter notebooks, even terminal and other Python-dependant extensions). This path was not configured anywhere, even the default interpreter has been changed. The problem existed on two independent machines, without any config sync between them. As a common thing I'd note that both VSCode instances were configured long before VSCode-Python switched to use a storage instead of config file for the Python Interpreter path.
I have managed to resolve most of the issues by removing the
~/.config/Code/Cache
directory (maybe also some others), but now it came again, when calling pytest from the Python test explorer.Basically, pytest works well when called from terminal, but fails when trying to discover any test. Please see the logs from "Output" for Python - the PYTHONPATH is set to contain the global path, and the invoked pytest does try to use
pluggy
from there instad of the one from venv.My suspicion is: the global path was at some point saved somewhere by the VSCode-Python extension. As the config files are no longer used for that, how could I looked up what are settings saved by the extension and remove the bad one?
This problem is extreamly irritating, couter-productive and comes back like a bumerang :(
Steps to reproduce:
Extreamly hard to say, I suspect you should have VSCode & the extension installed before the transition, and then do anything that would expect to use the local venv instead of global interpreter.
Diagnostic data
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Extension version: 2024.12.2
VS Code version: Code 1.92.0 (b1c0a14de1414fcdaa400695b4db1c0799bc3124, 2024-07-31T23:26:45.634Z)
OS version: Linux x64 6.5.0-45-generic
Modes:
python.languageServer
setting: PylanceUser Settings
Installed Extensions
A/B Experiments
The text was updated successfully, but these errors were encountered: