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

Interpreter always falling back to default in Jupyter notebook #13907

Closed
1 of 2 tasks
guidocioni opened this issue Jul 13, 2023 · 11 comments
Closed
1 of 2 tasks

Interpreter always falling back to default in Jupyter notebook #13907

guidocioni opened this issue Jul 13, 2023 · 11 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster notebook-execution Kernels issues (start/restart/switch/execution, install ipykernel) notebook-intellisense Intellisense & other language features in notebook cells for any language

Comments

@guidocioni
Copy link

Applies To

  • Notebooks (.ipynb files)
  • Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

I have two different conda environments (default, wetterdienst) which I want to obviously use as two different intepreters in Vscode.

When opening a Python file I can switch back and forth between the two different interpreters without issues.

For example here is an example of importing a package from the interpreter where it is installed

Screenshot 2023-07-13 at 11 35 51

and where it is not I do see an error

Screenshot 2023-07-13 at 11 36 00

Instead, in a Jupyter notebook

Screenshot 2023-07-13 at 11 42 18

This happens because, regardless of the interpreter chosen, Vscode is still using the interpreter of the "default" conda environment, which I can see if I try to import a package that exists in both.

Screenshot 2023-07-13 at 11 44 45

in this case it should take the pandas version installed in the wetterdienst conda environment.

NOTE: this has nothing to do with the actual execution of the Notebook, which depends on the Kernel, and it is working as expected. I don't understand why the kernel and interpreter versions in vscode-jupyter are allowed to be different...what is the sense in that?

VS Code Version

Version: 1.80.0 (Universal) Commit: 660393deaaa6d1996740ff4880f1bad43768c814 Date: 2023-07-04T13:39:33.766Z Electron: 22.3.14 ElectronBuildId: 21893604 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Darwin x64 22.5.0

Jupyter Extension Version

v2023.6.1101941928

Jupyter logs

Visual Studio Code (1.80.0, undefined, desktop)
Jupyter Extension Version: 2023.6.1101941928.
Python Extension Version: 2023.12.0.
Platform: darwin (x64).
No workspace folder opened.
11:41:00.189 [info] Start refreshing Interpreter Kernel Picker (1689241260189)
11:41:00.192 [info] Using Pylance
11:41:04.231 [info] End refreshing Interpreter Kernel Picker (1689241260189)
11:41:04.575 [warn] No interpreter for Pylance for Notebook URI "~/Downloads/test-wetterdienst.ipynb"
11:41:04.785 [info] Process Execution: ~/miniconda3/envs/wetterdienst/bin/python -m pip list
11:41:17.309 [info] Starting Kernel startUsingPythonInterpreter, .jvsc74a57bd0001f3971962c9ee7c92fa3573deab01210e17a4d7f9e524d462ea2afe861e700.~/miniconda3/envs/wetterdienst/python.~/miniconda3/envs/wetterdienst/python.-m#ipykernel_launcher  (Python Path: ~/miniconda3/envs/wetterdienst/bin/python, Conda, wetterdienst, 3.11.4) for '~/Downloads/test-wetterdienst.ipynb' (disableUI=true)
11:41:17.320 [info] Process Execution: ~/miniconda3/envs/wetterdienst/bin/python -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
11:41:17.339 [info] Process Execution: ~/miniconda3/envs/wetterdienst/bin/python -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"4cd07df2-7c48-4e95-8970-12d062d63e54" --shell=9002 --transport="tcp" --iopub=9004 --f=~/Library/Jupyter/runtime/kernel-v2-29897Fck7y39ycp2E.json
    > cwd: ~/Downloads
11:41:17.702 [info] ipykernel version & path 6.24.0, ~/miniconda3/envs/wetterdienst/lib/python3.11/site-packages/ipykernel/__init__.py for ~/miniconda3/envs/wetterdienst/bin/python
11:41:18.453 [warn] StdErr from Kernel Process 0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
11:41:18.817 [info] Started Kernel wetterdienst (Python 3.11.4) (pid: 30086)
11:41:18.817 [info] Started new session a498c763-5a43-4a9e-8657-595dce345162
11:41:18.854 [info] Process Execution: ~/miniconda3/envs/wetterdienst/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2023.6.1101941928-darwin-x64/pythonFiles/printJupyterDataDir.py
11:41:18.913 [warn] Got a non-existent Jupyer Data Dir file://~/.local/share/jupyter

Coding Language and Runtime Version

No response

Language Extension Version (if applicable)

No response

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

Local

@guidocioni guidocioni added the bug Issue identified by VS Code Team member as probable bug label Jul 13, 2023
@braindevices
Copy link

did you restart your kernel for pylance? From your log it looks like you already using correct kernel in notebook.

11:41:18.854 [info] Process Execution: ~/miniconda3/envs/wetterdienst/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2023.6.1101941928-darwin-x64/pythonFiles/printJupyterDataDir.py

@guidocioni
Copy link
Author

did you restart your kernel for pylance? From your log it looks like you already using correct kernel in notebook.

11:41:18.854 [info] Process Execution: ~/miniconda3/envs/wetterdienst/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2023.6.1101941928-darwin-x64/pythonFiles/printJupyterDataDir.py

I tried restarting multiple times. I'm not sure I understand what you mean: the kernel and the interpreter should be two different things.

@braindevices
Copy link

braindevices commented Jul 13, 2023

I mean the python language service. But anyway I can also reproduce this. But I do remember I can actually fix this via select interpreter and the restart eh language server.

Now, the trick fail to work. I can reproduce the bug.

The trick is from #6333

@guidocioni
Copy link
Author

I mean the python language service. But anyway I can also reproduce this. But I do remember I can actually fix this via select interpreter and the restart eh language server.

Now, the trick fail to work. I can reproduce the bug.

Yes, I have the feeling it started working weirdly since the last 2 or 3 major updates...they definitely changed something in the jupyter extension and of course made it even worse.

For me it is totally random: sometimes it does work after a while, sometimes it never works. Scrolling through a notebook sometimes makes the language server restarts... It has become just sluggish and really unstable.

@braindevices
Copy link

I looked at my python language server log, it is very clear ever time I refocus on the ipynb, the pylance switch to default interpreter.

2023-07-13 18:53:09.854 [info] [Info  - 6:53:09 PM] (13697)   Finding python search paths
2023-07-13 18:53:09.854 [info] [Info  - 6:53:09 PM] (13697)   Executing interpreter: 'python3'
2023-07-13 18:53:09.854 [info] [Info  - 6:53:09 PM] (13697)   Skipping '/usr/lib/python310.zip' because it is not a valid directory
2023-07-13 18:53:09.854 [info] [Info  - 6:53:09 PM] (13697)   Received 8 paths from interpreter

@braindevices
Copy link

braindevices commented Jul 13, 2023

@guidocioni I found a workaround. After create your notebook, save it to proper root directory (if you have multi root as I did). Then restart your vscode, it works again. It looks like change the interpreter on the fly for notebook does not work.
But you can still change it with default python interpreter setting per root folder (The per folder settings)

2023-07-13 19:24:36.583 [info] [Info  - 7:24:36 PM] (15643)   Executing interpreter: '/home/user/someproject/venv/bin/python'
2023-07-13 19:24:36.583 [info] [Info  - 7:24:36 PM] (15643)   Skipping '/usr/lib/python310.zip' because it is not a valid directory
2023-07-13 19:24:36.583 [info] [Info  - 7:24:36 PM] (15643)   Received 5 paths from interpreter

@rebornix rebornix assigned DonJayamanne and unassigned rebornix Dec 8, 2023
@rebornix rebornix added the notebook-execution Kernels issues (start/restart/switch/execution, install ipykernel) label Dec 8, 2023
@DonJayamanne
Copy link
Contributor

@braindevices @guidocioni Are you still running into this issue?

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster notebook-intellisense Intellisense & other language features in notebook cells for any language labels Dec 8, 2023
@braindevices
Copy link

braindevices commented Dec 15, 2023

I still see it and worse my work around at #13907 (comment) does not work some time. If I restart the vscode, sometimes it works again.

VS Code version: 1.85.1
Jupyter Extension version (available under the Extensions sidebar): v2023.11.1003402403
Python Extension version (available under the Extensions sidebar): v2023.22.1

@vscodenpa
Copy link

Hey @DonJayamanne, this issue might need further attention.

@guidocioni, you can help us out by closing this issue if the problem no longer exists, or adding more information.

@DonJayamanne DonJayamanne removed the info-needed Issue requires more information from poster label Mar 5, 2024
@DonJayamanne
Copy link
Contributor

@braindevices Are you still running into this issue with the latest versions?

@DonJayamanne DonJayamanne added the info-needed Issue requires more information from poster label Apr 2, 2024
@vscodenpa
Copy link

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@vscodenpa vscodenpa closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster notebook-execution Kernels issues (start/restart/switch/execution, install ipykernel) notebook-intellisense Intellisense & other language features in notebook cells for any language
Projects
None yet
Development

No branches or pull requests

5 participants