提到的问题并非特定于基于 conda 的虚拟环境。
我的配置:
Python 3.7.8,
VS代码:1.63.2,
操作系统:Windows 10 64 位,
venv 用于虚拟环境
我在虚拟环境中使用 python venv。当我在尝试运行时在 VS Code 中导入新的 .ipynb 文件时,出现错误“使用 Python 3.7.8(env_name:venv) 运行单元格需要 ipykernel 包”。
我点击弹出窗口进行安装,可以看到以下内容安装在我与 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。