-
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
Python doesn't fire environment changed when creating a new environment #21208
Comments
Thanks for the issue. What is the path to your venv? In order for Pylance to pick up changes to it, it has to be in the workspace itself. We watch for file changes in the workspace, but we can't watch for changes elsewhere (VS code provides us with the file watchers). This works for me as long as the venv is in the workspace. These sort of events should be in the log:
Looking at your log, it seems like the python path was never changed. It keeps showing this:
Whereas after I set the interpreter to the new virtual environment, I get something like so:
Do you perhaps have a pythonPath set in a pyrightconfig.json or a settings file? If you look at the output for the
|
The venv (
Yes, there was a bunch of 'add' and 'change' events triggered by the creation of the environment in the original log.
Yep. The path wasn't changed according to
If I perform anything described in the Actual behaviour, the server starts using the virtual environment (as expected):
Selecting an environment manually works as expected. The issue described happens only when a user creates an environment via
No. Moreover, I've tested the case on another computer that has never had neither vscode nor python installed and its behaviour has been exactly the same. |
Okay thanks. This sounds like a bug in the Python extension. It may be forgetting to fire an event that indicates the interpreter changed. I don't reproduce this issue myself, but you might want to double check what your Python extension version is. I have the following: Python extension: 2022.20.2 I also tried this one: Python extension: 2023.1.10091012 Both of those worked for me. |
Python extension is 2023.6.0. I'll check if the issue persists in older versions. |
Thanks for the bug report! We investigate issues in order based on priority and severity, which includes the impact it has on your ability to use the extension to do productive work, and the number of people affected. If other users come forward and leave a comment demonstrating they are seeing/reproducing the problem then we will raise this issue's priority. Thanks for understanding and the patience! |
Given the path is changed event should be fired. Perhaps language server component doesn't subscribe to it correctly. Reassigning to LS as things look good from environment side, we've to make sure
|
@debonte Can you look into this or assign someone to investigate this? |
We don't subscribe to an event. The Python Extension just sends a configuration change message itself when a creating a new environment. That code is here: Is it possible the 'Create New Environment' is not firing the event? I still think this is a python core extension issue. We are not getting the config change message. |
I can repro the issue if I delete the folder and start over again. The config message won't be sent because the internal store says the path is the same and it doesn't fire the change event. That's in the Similarly, if I set I think there's an issue with the fetching of the python path from storage. Storage should be cleared if the value is invalid. That doesn't sound like the user's problem though. I can only repro this issue if the folder was already opened at some point and then deleted. |
@mpekurin We added more logs, and pushed a new-build, can you try getting the logs again?
Output for
|
@karrtikr sure
|
I didn't notice this before but this is true. If I do the repro steps in a folder that had never ever been opened in vscode before everything works as expected. |
I think you missed to set "Set python.logging.level to debug in User settings" as asked earlier, maybe you didn't reload?
I see, in that case try |
Seems like
Any action that makes the language server to restart ( |
I would expect |
@mpekurin Did you perform the steps to repro in #21208 (comment) before capturing the logs? |
It solves it till a directory is cached again (e.g. clear cache and reload -> create a venv in a
Yep. |
Oh yeah, if you delete the venv folder and attempt to recreate it, we won't be firing an event. Addressing this case would involve incorporating extra logic that may not be justifiable. If you come across this situation in your everyday usage, please feel free to let us know, and we'll gladly reassess it. |
Environment data
Code Snippet
Repro Steps
Python: Create Environment...
->Venv
.pip install github
.import pip
andimport github
.Expected behavior
Pylance uses the newly created environment.
Pressing F12 (Go To Definition) on
pip
opens pip's__init__.py
from the venv. Pylance doesn't showImport "github" could not be resolved
error.Actual behavior
Pylance continues to use global environment, even though after creating the environment python extension shows
We have selected the following environment: \path\to\venv
notification and the status bar shows that the venv interpreter is selected.Pressing F12 (Go To Definition) on
pip
opens pip's__init__.py
from the global environment. Pylance showsImport "github" could not be resolved
error because (according to logs) it still tries to find the package in the global environment.To make pylance actually use the created environment, the user have to do one of the following:
Python: Restart Language Server
.Developer: Reload Window
.Logs
I've had to remove 'add' and 'change' evens between
[Info - 4:28:17 PM]
and[Info - 4:28:50 PM]
because github limits body to 65536 characters. These events were triggered byPython: Create Environment...
.The text was updated successfully, but these errors were encountered: