问题描述
当使用VS Code & Anaconda & JupyterNotebook时,在Anaconda的虚拟环境中安装了Jupyter,通过VSCode的Jupyter插件打开ipynb文件,执行python代码时报错:
Failed to start the Kernel.
Error code from Jupyter: 1
Error executing Jupyter command 'notebook': [Errno 2] No such file or directory
同时在VSCode通过终端直接执行
jupyter notebook
可以启动jupyter服务器,通过URL可以通过浏览器访问,说明jupyter的安装是正常的。
解决方法
需要在VSCode中激活当前安装jupyter的conda环境。
1. 在VSCode中 ctrl + shift + P
2. 输入 Select Interpreter
3. 选择Python: Select Interpreter,会显示你全部的conda虚拟环境以及其他的Python版本
4. 选择你要的环境。
5. 选择Jupyter: Select Interpreter to Start Jupyter Server,操作同上。
6. 完
参考:python - Activating Anaconda Environment in VsCode - Stack Overflow