-
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 & Jupyter extension fail to detect upgraded Python #24364
Comments
We typically don't re-run detection is some of these cases. A workaround is to run |
@karthiknadig, thanks for the explanation. I ran that command and it did, indeed "forget about" the old Python versions and found the updated version. Unfortunately, if also forgot about my virtual environment and did not find it when I selected It would be helpful to add to the documentation the steps needed when the system Python is upgraded:
Step 3 above is needed in systems like Linux Mint (Ubuntu base) where the system interpreter is "managed" and does not easily allow installing user-specific packages. |
You should be able to see in the logs for Output > Python and Output > Python Locator to see what it is looking for. |
@karthiknadig, thanks for the suggestion. It seems that the internals found the virtual environment, but not the I ran another
The whole process seems to have been repeated a couple more times though I triggered a refresh only once. The above suggests that the code did find my environment. In fact, the code did so a total of about 50 times. (Why so many?) However, if I then do Notice that the virtual environment does not appear on the list though it is marked as the selected interpreter. The expected behavior is that, if the code did discover my virtual environment, that it would be available as one of the interpreters so I can select it. Any reason that it does not appear in the UI interpreter list? A subtle point is that the first time I did the above, my virtual environment was not selected. The second time, the virtual environment selection appeared to "survive" the All of this would just be an annoying UI glitch if it were not then for Jupyter. Using Now, to be complete, let's select another interpreter using Let's try one more trick. Again run Finally, I used Fortunately, after I manually configure the virtual environment, it does then show up in the above Jupyter In fact, once I configure my environment manually, the notebook then automatically selects that kernel, likely because the kernel name is stored in the notebook itself. Thus, the Bottom line: this is all rather fiddly and could, perhaps, be streamlined a bit to avoid the need to ask for help for such a simple task. To be clear, the following would be helpful:
|
@paul-rogers Can you check what the locator has two options |
@karthiknadig, the |
@DonJayamanne Any idea what might be going on here? I am not fully familiar with how the kernel picker finds/filters things. |
FWIW, while debugging Jupyter Issue #16185 , I enabled
At which point the kernel starts the kernel for my notebook, etc. To my naive eyes, it seems that the search did not find my virtual environment. It looks like it then does This raises two questions: why does it not locate the virtual environment during the various searches? Why does it want to "hide" the virtual environment once it finds it? |
@paul-rogers Lets try to focus on one thing at a time.
What is this virtual environment?
We're not hiding Envirolnments, we're hiding a kernel spec, (the file hiddent is For now lets ignore Jupyter, and deal with Python extension and not seeing the environments you expect to see |
@DonJayamanne, sure, let's leave Jupyter out of the discussion. I upgraded the Python extension as you suggested and restarted VS Code. I'm now on version
Sorry that I was not clear about the virtual environment. I have just one virtual environment, the one in I created the environment in
Going to that the
One cool feature I stumbled upon that is worth mentioning: One can find the Out of curiosity, I went ahead and set Just to nit pick, the top comment could also be clearer, suggestions in bold.
That is, the folder does not contain "a list", it contains the virtual environments directly. Also, the setting is not "a list", it must be a single directory (it seems). To check this, I changed the setting to include my original The settings search for
The comment "supports pyenv, ... by default". Is why I placed my virtual environment in OK, so perhaps the default is really the name To test this, while leaving So, perhaps the easiest fix is to change the last line of the setting description. Possible change in bold:
This leaves us with three possible bugs/changes/clarifications:
I hope this gives you the information you need to resolve this issue. |
I think this comment is referring to the environment managers Thanks for highlighting these, we'll update the comments/descriptions in the settings |
I was about to suggest that this is just a documentation improvement request. But, further exploration showed that there are bugs when using the interpreter as a kernel in Jupyter. Once I manually set
Had that wording existed, I would have not had to try to sort things out myself. It turns out that Thanks for the help. |
Here's a description why I cleaned up the extra virtual environments left over from my attempts to set things up. I now have only The behavior of these two entries differs. If I select the first one, with the leading tilde, Note how the text for the selected interpreter has the tilde, the highlighted one does not. Now, if I select the second one, the one without the tilde, and again use Note that now the selected path is Just to test, I tried removing my So, the user has to know to select the entry with the tilde (to get an absolute path), but understand that the UI will mark the one without the tilde. I think this is just a bit confusing. |
I tried to work around the above behavior by renaming my virtual environment's folder from To double-check, I restarted VS Code, and ran |
So, the one thing which does work is to ignore the With this setting, my virtual environment appears (once) in the I also found (as described in the other issue), that configuring So, the bottom line is that |
@paul-rogers There are lots of concepts here that I think are getting mixed. About
|
@karthiknadig, thanks for the explanation. Do note the bizarre behavior described above when I added my virtual environment using In particular, see the description of the duplicate entries and the use of Thanks for your help. |
That is a bug we will investigate. I will create a tracking bug for that using your comment. (#24376) |
Type: Bug
Behaviour
After an OS upgrade replaced an old Python with a new version, VS Code fails to detect the new version.
Steps to reproduce
I use Linux Mint. Version 21 included Python 3.10.12 with symlinks in
/bin/python3
and/usr/bin/python3
. VS code detected these and things worked just fine.I recently upgraded to Mint version 22, which removed the Python 3.10.12 and replace it with Python 3.12.3. In a shell:
However, if I use
Python: Select Interpreter
I get the following:Notice that VS Code still believes that the system Python is 3.10.12. Just to be clear: I have restarted VS Code multiple times since the OS upgrade.
I reviewed the documentation. This document says that Python will detect the Python versions automatically. Clearly, it did not.
Python 3.10.12 no longer exists on the system. Yet, the Python extension seems to believe that the Python in
/bin/python3
is that version. Perhaps the version information is cached. However, the documentation provides no hints (which I could find) to tell VS Code to flush its cache and to go out and look to see which version is actually installed.At the same time, Jupyter fails to detect this version also. Create a new notebook. Select "Select Interpreter." Only the non-existent 3.10.12 interpreter is listed. Now, it could be that Jupyter fails to find the system Python because that version is managed by the OS and I've not installed the required Python modules, though the documentation says that I'll be prompted to install them.
My workaround was to create a virtual environment (in a terminal). In a terminal, with the virtual environment added to the path:
The documentation says that this virtual environment will be detected automatically, since it is in
~/pyenv
. However, it was not. I was able to configure it viaPython: Select Interpreter/Enter Interpreter Path
.Then, I had to install
IPyKernel
by hand after which I could finally select the correct interpreter in a new Juypter notebook.Specific Issues
IPyKernel
module as promised in the documentation.Diagnostic data
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Extension version: 2024.16.1
VS Code version: Code 1.95.0 (912bb683695358a54ae0c670461738984cbb5b95, 2024-10-28T20:16:24.561Z)
OS version: Linux x64 6.8.0-47-generic
Modes:
python.languageServer
setting: PylanceUser Settings
Installed Extensions
System Info
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
webnn: disabled_off
A/B Experiments
The text was updated successfully, but these errors were encountered: