VSCode Jupyter 加载了错误版本的 python [英] VSCode Jupyter loads incorrect version of python

查看:86
本文介绍了VSCode Jupyter 加载了错误版本的 python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VSCode 的 Jupyter 实际上并未运行它显示在屏幕左下方的 Python 版本.

VSCode's Jupyter isn't actually running the version of python that it displays in the lower left of the screen.

下面,它声称运行的是 3.9.1,但单元格的输出显示它确实运行的是 3.7.9.

Below, it purports to be running 3.9.1, but the output of the cell shows that it is indeed running 3.7.9.

我通过以下方式选择了显示的 rl 环境:Select environment to start Jupyter Server.

I selected the displayed rl environment via: Select environment to start Jupyter Server.

什么不起作用:

  • 重启 Jupyter 内核
  • 选择不同的环境(它们实际上都运行 3.7.9,而不管 env 的 python)

额外信息:

Python 输出:

> conda --version
> pyenv root
> python3.7 ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~/.local/share/miniconda3/envs/rl/bin/python ~/.vscode/extensions/ms-python.python-2020.12.424452561/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> conda info --json
Starting Pylance language server.
Python interpreter path: ~/.local/share/miniconda3/envs/rl/bin/python
> conda env list
> conda env list

是的,最后列出的解释器确实是 v3.9.1:

Yes, that last listed interpreter really is v3.9.1:

% ~/.local/share/miniconda3/envs/rl/bin/python --version
Python 3.9.1

Jupyter 输出:

Jupyter Output:

User belongs to experiment group 'jupyterTest'
> ~/.local/share/miniconda3/envs/rl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py -c "import notebook"
> ~/.local/share/miniconda3/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py -c "import jupyter"
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py jupyter kernelspec --version
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~/.local/share/miniconda3/envs/nndl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.jupyter_daemon -v
> ~/.local/share/miniconda3/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
> ~/.local/share/miniconda3/envs/rl/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
Started kernel Python 3
> ~/.local/share/miniconda3/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.12.414227025/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v

这个最终列出的 python 是不正确的,未选择的版本:

This final listed python is the incorrect, non-selected version:

% ~/.local/share/miniconda3/bin/python --version
Python 3.7.9

为什么当正确的 ~/.local/share/miniconda3/envs/rl/bin/python 列在上面时使用这个版本?

Why is this version being used when the correct ~/.local/share/miniconda3/envs/rl/bin/python is listed immediately above?

推荐答案

最终对我有用的是:

  1. 关闭 VSCode
  2. .ipynb 窗格的右上角,将 Python 版本更改为所需的 conda 环境
  3. 启动内核
  1. Close VSCode
  2. In .ipynb pane's top right, change version of Python to the desired conda environment
  3. Start the kernel

更改内核然后重新启动它似乎不起作用.

Changing the kernel and then restarting it didn't seem to work.

这篇关于VSCode Jupyter 加载了错误版本的 python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆