Python 需要安装 ipykernel
Python requires ipykernel to be installed
我在 VS 代码中使用 Jupyter Notebook 时遇到问题。屏幕显示“Python 3.7.8 requires ipykernel to be installed
”。我按照弹出窗口安装了ipykernel。它仍然不起作用。附上截图。这让我很困扰。有人可以帮我吗?非常感谢。
原因是您当前的VSCode终端在环境“Deeplearning_Env
”中,所以“ipykernel
”安装在环境“Deeplearning_Env
”中弹出框中显示的环境“base conda
”。
解决:请使用快捷键Ctrl+Shift+`打开一个新的VScode终端,会自动进入当前选择的VSCode环境(VSCode左下角) ,并激活这个 conda 环境:
然后根据弹框提示点击安装“ipykernel
”。
或者,我们也可以手动安装“ipykernel
”:(pip install ipykernel
)
另外,对于新建的Python环境(没有安装“ipykernel
”),打开Jupyter文件前,请先刷新VSCode终端,输入当前选择的环境。对于conda环境,我们需要先激活后才能使用。
检查:检查“ipykernel
”的安装:
更多参考:Environment in VSCode.
更改 JSON 架构并指向您的环境。
如果遇到问题,请创建新环境。
另请参阅:
就做一个:
pip install ipykernel --upgrade
安装在conda(base)
环境中的pyzmq
包导致了它。可以通过在conda(base)环境下卸载重装'pyzmq'包解决问题
pip uninstall pyzmq
pip install pyzmq
详情可参考here
最近我 运行 遇到了这个问题,我个人认为如果您使用的是 conda 环境,这个问题就会特别出现。即使您在正确的环境中升级了 ipykernel,问题仍然存在。在要与 Jupyter 笔记本一起使用的 conda 环境中安装 nb_conda_kernels
包。
conda install -n notebook_env nb_conda_kernels
将上述命令中的notebook_env
替换为您实际使用的环境名称。查看此 repository 以供进一步参考。
在我的例子中,我必须 pip install jupyter
,而不是错误消息暗示的 ipykernel
。
我遇到了同样的问题,花了一整天的时间试图解决它。对我有用的是为 anaconda 安装 Jupyter 依赖项:
> conda install jupyter
我在我的基本环境中安装了它。在此之后 VSCode 工作没有任何错误。
也许您可以尝试在终端中输入此命令。让我们看看会发生什么。
python -m ipykernel
我在输入此命令后遇到了错误。
ImportError: cannot import name 'AsyncGenerator'
修复来自
pip install --upgrade prompt-toolkit==2.0.1
提到的问题并非特定于基于 conda 的虚拟环境。
我的配置:
Python 3.7.8,
VS代码:1.63.2,
OS: Windows 10 64 位,
虚拟环境的 venv
我正在使用 python venv 作为虚拟环境。当我在 VS Code 中导入一个新的 .ipynb 文件并尝试 运行 它时,它给出了错误“运行 cells with Python 3.7.8(env_name:venv)需要 ipykernel 包。
我点击弹出窗口进行安装,可以看到以下内容正在安装在选定的虚拟机中 environment/kernel 我正在使用我的 Jupyter 笔记本。
xxx/xxx/../python.exe -m pip install -U ipykernel
最后,安装的软件包:
Installing collected packages: wcwidth, traitlets, parso, tornado, pyzmq, pygments, prompt-toolkit, pickleshare, nest-asyncio, matplotlib-inline, jupyter-core, jedi, entrypoints, decorator, backcall, jupyter-client, ipython, debugpy, argcomplete, ipykernel
Successfully installed argcomplete-2.0.0 backcall-0.2.0 debugpy-1.5.1 decorator-5.1.1 entrypoints-0.3 ipykernel-6.6.1 ipython-7.31.0 jedi-0.18.1 jupyter-client-7.1.0 jupyter-core-4.9.1 matplotlib-inline-0.1.3 nest-asyncio-1.5.4 parso-0.8.3 pickleshare-0.7.5 prompt-toolkit-3.0.24 pygments-2.11.2 pyzmq-22.3.0 tornado-6.1 traitlets-5.1.1 wcwidth-0.2.5
您可以直接在所选环境中安装ipykernel开始。
我在 VS 代码中使用 Jupyter Notebook 时遇到问题。屏幕显示“Python 3.7.8 requires ipykernel to be installed
”。我按照弹出窗口安装了ipykernel。它仍然不起作用。附上截图。这让我很困扰。有人可以帮我吗?非常感谢。
原因是您当前的VSCode终端在环境“Deeplearning_Env
”中,所以“ipykernel
”安装在环境“Deeplearning_Env
”中弹出框中显示的环境“base conda
”。
解决:请使用快捷键Ctrl+Shift+`打开一个新的VScode终端,会自动进入当前选择的VSCode环境(VSCode左下角) ,并激活这个 conda 环境:
然后根据弹框提示点击安装“ipykernel
”。
或者,我们也可以手动安装“ipykernel
”:(pip install ipykernel
)
另外,对于新建的Python环境(没有安装“ipykernel
”),打开Jupyter文件前,请先刷新VSCode终端,输入当前选择的环境。对于conda环境,我们需要先激活后才能使用。
检查:检查“ipykernel
”的安装:
更多参考:Environment in VSCode.
更改 JSON 架构并指向您的环境。
如果遇到问题,请创建新环境。
另请参阅:
就做一个: pip install ipykernel --upgrade
安装在conda(base)
环境中的pyzmq
包导致了它。可以通过在conda(base)环境下卸载重装'pyzmq'包解决问题
pip uninstall pyzmq
pip install pyzmq
详情可参考here
最近我 运行 遇到了这个问题,我个人认为如果您使用的是 conda 环境,这个问题就会特别出现。即使您在正确的环境中升级了 ipykernel,问题仍然存在。在要与 Jupyter 笔记本一起使用的 conda 环境中安装 nb_conda_kernels
包。
conda install -n notebook_env nb_conda_kernels
将上述命令中的notebook_env
替换为您实际使用的环境名称。查看此 repository 以供进一步参考。
在我的例子中,我必须 pip install jupyter
,而不是错误消息暗示的 ipykernel
。
我遇到了同样的问题,花了一整天的时间试图解决它。对我有用的是为 anaconda 安装 Jupyter 依赖项:
> conda install jupyter
我在我的基本环境中安装了它。在此之后 VSCode 工作没有任何错误。
也许您可以尝试在终端中输入此命令。让我们看看会发生什么。
python -m ipykernel
我在输入此命令后遇到了错误。
ImportError: cannot import name 'AsyncGenerator'
修复来自
pip install --upgrade prompt-toolkit==2.0.1
提到的问题并非特定于基于 conda 的虚拟环境。
我的配置: Python 3.7.8, VS代码:1.63.2, OS: Windows 10 64 位, 虚拟环境的 venv
我正在使用 python venv 作为虚拟环境。当我在 VS Code 中导入一个新的 .ipynb 文件并尝试 运行 它时,它给出了错误“运行 cells with Python 3.7.8(env_name:venv)需要 ipykernel 包。
我点击弹出窗口进行安装,可以看到以下内容正在安装在选定的虚拟机中 environment/kernel 我正在使用我的 Jupyter 笔记本。
xxx/xxx/../python.exe -m pip install -U ipykernel
最后,安装的软件包:
Installing collected packages: wcwidth, traitlets, parso, tornado, pyzmq, pygments, prompt-toolkit, pickleshare, nest-asyncio, matplotlib-inline, jupyter-core, jedi, entrypoints, decorator, backcall, jupyter-client, ipython, debugpy, argcomplete, ipykernel
Successfully installed argcomplete-2.0.0 backcall-0.2.0 debugpy-1.5.1 decorator-5.1.1 entrypoints-0.3 ipykernel-6.6.1 ipython-7.31.0 jedi-0.18.1 jupyter-client-7.1.0 jupyter-core-4.9.1 matplotlib-inline-0.1.3 nest-asyncio-1.5.4 parso-0.8.3 pickleshare-0.7.5 prompt-toolkit-3.0.24 pygments-2.11.2 pyzmq-22.3.0 tornado-6.1 traitlets-5.1.1 wcwidth-0.2.5
您可以直接在所选环境中安装ipykernel开始。