Cannot Switch to Different Python kernel
See original GitHub issueEnvironment data
- VS Code version: Version: 1.54.3 (Universal) Commit: 2b9aebd5354a3629c3aba0a5f5df49f43d6689f8
- Jupyter Extension version (available under the Extensions sidebar): v2021.3.619093157
- Python Extension version (available under the Extensions sidebar): v2021.3.658691958
- OS (Windows | Mac | Linux distro) and version: macOS Big Sur 11.2.3 (ARM 64 arch)
- Python and/or Anaconda version: 3.8.2, conda 4.9.2
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
- Jupyter server running: Local
Expected behaviour
When selecting a specific Python Kernel (which are found) Jupyter VS Code should use that one, at least after a restart. In my workspace settings, I have explicitly set the option "python.pythonPath": "/opt/homebrew/Caskroom/miniforge/base/envs/nlpsimple/bin/python"
, where nlpsimple
is my desired environment.
Actual behaviour
Running sys.executable
outputs '/opt/homebrew/Caskroom/miniforge/base/bin/python'
, so apparently VS Code Jupyter is unable to switch to a different environment. I have switched to my desired environment in the internal terminal before re-starting the kernel and re-running this command with the same result.
It seems that Jupyter VS Code tries to use my system installation of Python to start the IPython Kernel. However, my environments use 3.8 since I need PyTorch, while my system installation has 3.9 – see logs below.
Steps to reproduce:
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
- I am using Jupyter VS Code in a pretty fresh install since VS Code just recently released as stable for M1 Macs. Other than the above-mentioned setting in my workspace, there is nothing I changed with the base settings, and I have not yet worked using VS Code Jupyter in this new installation (which should be self-contained from the Insiders edition I was using before)
- The environments were installed before, however.
Logs
Output for Jupyter
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Jupyter
)
[I 09:51:42.430 NotebookApp] Kernel shutdown: a9c72ff0-b1eb-44ee-b83e-a3ba17234563
> /opt/homebrew/Caskroom/miniforge/base/envs/nlpsimple/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2021.3.619093157/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
[I 09:51:43.013 NotebookApp] Kernel started: 4f1478ad-4875-4935-b196-5dd89c57c141, name: python3
[W 09:51:43.017 NotebookApp] delete /t-20bc9970-c10a-498b-9b6a-b8f48d942aff.ipynb
Error 2021-03-19 09:54:42: KernelSpec has interpreter information, however a matching interpreter could not be found for /opt/homebrew/opt/python@3.9/bin/python3.9
Error 2021-03-19 09:54:43: KernelSpec has path information, however a matching interpreter could not be found for /opt/homebrew/opt/python@3.9/bin/python3.9
Error 2021-03-19 09:59:19: KernelSpec has interpreter information, however a matching interpreter could not be found for /opt/homebrew/opt/python@3.9/bin/python3.9
> /opt/homebrew/Caskroom/miniforge/base/envs/nlpsimple/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2021.3.619093157/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
> /opt/homebrew/Caskroom/miniforge/base/envs/nlpsimple/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2021.3.619093157/pythonFiles/pyvsc-run-isolated.py pip list
Error 2021-03-19 09:59:20: KernelSpec has path information, however a matching interpreter could not be found for /opt/homebrew/opt/python@3.9/bin/python3.9
> /opt/homebrew/Caskroom/miniforge/base/envs/nlpsimple/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2021.3.619093157/pythonFiles/pyvsc-run-isolated.py pip list
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Thanks for filing this issue. I believe we have addressed this in our current development version of the extension.
In order to validate the fixes please could you:
Thanks
I have the same problem. The only way to solve it is to change the jupyter server from the vscode default to the link given by jupyter notebook in cmd/powershell (I opened another jupyter notebook by command). The link is something like “http://localhost:8888/?token=xxxxxxxx or http://127.0.0.1:8888/?token=xxxxxxx”. When I changed the jupyter server to this one, I can import every module. Also I found a strange thing : by changing the jupyter serve between the above two choices, when you switch back to vscode’s default server at some time point (seem to be random), it will be possible to import the module again!