简体   繁体   English

VS Code Jupyter 扩展:远程笔记本未启动

[英]VS Code Jupyter Extension: Remote notebook not starting

I'm trying to connect to a remote Jupyter notebook using the VS Code Jupyter extension.我正在尝试使用 VS Code Jupyter 扩展连接到远程 Jupyter 笔记本。

Using CMD + Shift + P<\/kbd> -> Jupyter: Enter the URL of local\/remote Jupyter notebook<\/code> brings up an input field, where I enter the address of the notebook.使用CMD + Shift + P<\/kbd> -> Jupyter: Enter the URL of local\/remote Jupyter notebook<\/code>会弹出一个输入字段,我在其中输入笔记本的地址。 Afterwards an input field asking for the token is shown.之后显示一个要求令牌的输入字段。 When I enter the token and press Enter<\/kbd> , nothing happens.当我输入令牌并按Enter<\/kbd>时,没有任何反应。

I tried to connect using VS Code for MacOS and Linux Mint.我尝试使用 VS Code for MacOS 和 Linux Mint 进行连接。 Using a notebook hosted on localhost:8888<\/code> and well an notebook hosted on a different computer within my home network 192.168.0.11:8888<\/code> .使用托管在localhost:8888<\/code>上的笔记本以及托管在我的家庭网络192.168.0.11:8888<\/code>内的另一台计算机上的笔记本。 Both ways do not work.两种方式都行不通。

I can access the Jupyter notebooks via browser.我可以通过浏览器访问 Jupyter 笔记本。

When I start VS Code per command line with a Python environment, that has jupyter<\/code> installed, I am also able to run a notebook (purely) within VS Code.当我使用安装了jupyter<\/code>的 Python 环境按命令行启动 VS Code 时,我还可以在 VS Code 中运行笔记本(纯粹)。 If I do not start VS Code within a Python environment with jupyter<\/code> installed, I am not able to run any notebooks (but this seems to be an know issue).如果我没有在安装了jupyter<\/code>的 Python 环境中启动 VS Code,我将无法运行任何笔记本(但这似乎是一个已知问题)。

How do I solve this issue (connect to a remote notebook)?我该如何解决这个问题(连接到远程笔记本)?

Is someone able to connect to a remote notebook?有人能够连接到远程笔记本吗? (If yes, how?) (如果是,如何?)

"

使用以下命令:

jupyter notebook --ip=0.0.0.0 --port=8080 --allow-root

At first glance, it would appear that you got the token incorrect.乍一看,您似乎得到了不正确的令牌。 When I chose the option to enter the Url of a remote server and got the token wrong, the only indication things weren't working was the fact that I couldn't execute any Python code.当我选择输入远程服务器的 URL 的选项并得到错误的令牌时,唯一的迹象表明事情不正常是我无法执行任何 Python 代码。 And, when I used that same Url in a browser, I got a web UI that asked me to enter a token.而且,当我在浏览器中使用相同的 Url 时,我得到了一个要求我输入令牌的 Web UI。 Once I found and entered a valid token, I got their nice little UI for working in notebooks.一旦我找到并输入了一个有效的令牌,我就得到了他们在笔记本上工作的漂亮的小 UI。

As for my experience, I just got it working in VsCode a few moments ago: I have a .ipynb file open in VsCode, it's switched to being pointed at my remote Jupyter Server, and I can execute code against it and get output.至于我的经验,我刚刚在 VsCode 中运行它:我在 VsCode 中打开了一个 .ipynb 文件,它被切换为指向我的远程 Jupyter 服务器,我可以针对它执行代码并获得输出。

Overview of my setup我的设置概述

Prerequisites先决条件

  1. I have VsCode setup with the Python, Pylance, Jupyter, Jupyter Keymap, and Jupyter Notebook Renderers extensions.我使用 Python、Pylance、Jupyter、Jupyter Keymap 和 Jupyter Notebook Renderers 扩展设置了 VsCode。 I did these as part of my initial forays into Python and then using Jupyter Notebooks.我将这些作为我最初涉足 Python 的一部分,然后使用 Jupyter Notebooks。
    • While I've been able to use Jupyter Notebooks and have autocomplete/Intellisense working against my local machine, I don't know enough to say which extensions are required for this, nor if there's some setup I did as part of that which is critical for this remote setup to work.虽然我已经能够使用 Jupyter Notebooks 并在我的本地计算机上使用自动完成/智能感知,但我不知道需要哪些扩展,也没有我做的一些设置作为关键的一部分使此远程设置正常工作。
  2. I'm on a Windows 10 box and have WSL2 setup with a Ubuntu image and Docker is installed and setup within it.我在 Windows 10 机器上,并使用 Ubuntu 映像设置 WSL2,并在其中安装和设置 Docker。

The steps步骤

  1. Install a docker image that has Spark, Python, PySpark, and Jupyter all setup for you: docker run -d --name jspark -p 8888:8888 jupyter/pyspark-notebook安装一个包含 Spark、Python、PySpark 和 Jupyter 的 docker 镜像: docker run -d --name jspark -p 8888:8888 jupyter/pyspark-notebook
  2. Get the auth token: docker exec -it jspark jupyter server list获取授权令牌: docker exec -it jspark jupyter server list
  3. Get the IP address of eth0 : ip addr获取eth0的 IP 地址: ip addr
  4. Using the output of the previous 2 steps, build the final URL that you can use from the host (Windows) OS to connect to the Jupyter server.使用前 2 个步骤的输出,构建最终 URL,您可以使用该 URL 从主机 (Windows) 操作系统连接到 Jupyter 服务器。
  5. Prove it works by navigating to it in a browser.通过在浏览器中导航到它来证明它有效。
  6. Over in VsCode, use that same URL as the location of the remote Jupyter Server.在 VsCode 中,使用与远程 Jupyter 服务器位置相同的 URL。

If everything goes as expected, VsCode will "think" for a bit while it tests the connection, and then you'll see that "play" button show up to the left of your Python cell(s).如果一切按预期进行,VsCode 会在测试连接时“思考”一段时间,然后您会看到“播放”按钮显示在 Python 单元格的左侧。

I used this code to prove it was working:我用这段代码来证明它是有效的:

from pyspark.sql import SparkSession

spark = SparkSession.builder.getOrCreate()
df = spark.read.json("/usr/local/spark/examples/src/main/resources/people.json")
df.show()

And now I can move on to improving the experience, since I have a known working baseline.现在我可以继续改进体验,因为我有一个已知的工作基线。 I'm hoping to get autocomplete/Intellisense working, but based on what I've read so far, I'm not holding my breath.我希望让自动完成/智能感知工作,但根据我目前所读到的内容,我并没有屏住呼吸。

The problem I encountered is as follows我遇到的问题如下

command 'jupyter.selectExistingNotebook' not found

I installed the Jupyter extension on vscode.我在 vscode 上安装了 Jupyter 扩展。 Follow the instructions: Remote Jupyter kernel on Server / Docker按照说明操作:Server / Docker 上的远程 Jupyter 内核

Try this to connect to a remote Jupyter kernel running on a server, or inside Docker container:尝试连接到在服务器上或 Docker 容器内运行的远程 Jupyter 内核:

Start a remote Jupyter Notebook or headless KernelGateway启动远程 Jupyter Notebook 或无头 KernelGateway

Find the token in the output of the Jupyter server logs: http://jupyter-notebook.readthedocs.io/en/latest/security.html在 Jupyter 服务器日志的输出中找到令牌: http ://jupyter-notebook.readthedocs.io/en/latest/security.html

Then in VS Code: ctrl+shift+p然后在 VS Code 中:ctrl+shift+p

Jupyter: Enter the url of local/remote Jupyter Notebook Jupyter:输入本地/远程 Jupyter Notebook 的 url

I only installed docker and run the container.我只安装了 docker 并运行了容器。

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

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