简体   繁体   English

使用 WSL 2 的 VS Code 中的 Jupyter Notebooks 不起作用

[英]Jupyter Notebooks in VS Code using WSL 2 are not working

I want to use Jupyter Notebooks inside VS Code running within WSL 2. Regular Python works within WSL without a problem, that means the base conda enviroment is connected and I can run .py files.我想在 WSL 2 中运行的 VS Code 中使用 Jupyter Notebooks。常规 Python 在 WSL 中运行没有问题,这意味着基本 conda 环境已连接,我可以运行 .py 文件。 Moreover, I'm able to run the command jupyter notebook which will start the notebook server within WSL exposing the localhost to the Windows system.此外,我能够运行命令jupyter notebook ,它将在 WSL 中启动笔记本服务器,将本地主机暴露给 Windows 系统。

However, I want to test the new Jupyter Notebook feature within VS Code, which is not working for me;但是,我想在 VS Code 中测试新的 Jupyter Notebook 功能,这对我不起作用; VS Code shows: Jupyter Server: No Kernel and Python: Not Started (see screenshot below). VS Code 显示: Jupyter Server: No KernelPython: Not Started (请参见下面的屏幕截图)。

My testing machine is:我的测试机是:

  • WSL 2 (using Pengwin distribution) on Windows 20H1 (19041.21) Windows 20H1 (19041.21) 上的 WSL 2(使用 Pengwin 发行版)
  • VS Code 1.41 (having the Python extension installed) VS Code 1.41(安装了 Python 扩展)
  • Anaconda蟒蛇

What I did:我做了什么:

  1. Open WSL打开 WSL
  2. Open VS Code in my target directory ( code . )在我的目标目录( code . )中打开 VS Code
  3. Create a new Notebook file from the command palette Python: Create New Blank Jupyter Notebook从命令面板Python: Create New Blank Jupyter Notebook创建一个新的 Notebook 文件Python: Create New Blank Jupyter Notebook
  4. Create dummy print("test")创建虚拟print("test")
  5. Run Cell will trigger the warning: Run Cell 会触发警告:

在此处输入图片说明

Is there anything I'm missing?有什么我想念的吗?

The VS Code insiders actually works out of box with Jupyter notebooks. VS Code 内部人员实际上与 Jupyter 笔记本一起开箱即用。 Just remember to run code-insiders .请记住运行code-insiders . instead of code .而不是code . . .

Another solution would be, according to this website , start the VS Code in windows, then use WSL 2 as a remote server.另一种解决方案是,根据这个网站,在 Windows 中启动 VS Code,然后使用 WSL 2 作为远程服务器。

The code installation on wsl2 needs a restart to work properly, I was told by a notification, and in the question's comments you may see people experiencing the same issue(' it's working now. not sure why'). wsl2 上的代码安装需要重新启动才能正常工作,通知告诉我,在问题的评论中,您可能会看到人们遇到同样的问题(“现在正在工作。不知道为什么”)。 So before looking upon any elaborate solution, just restart code.因此,在查看任何精心设计的解决方案之前,只需重新启动代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM