简体中文

前言

原本我想在PyCharm专业版中搞了远程开发,但是突然发现,用 jupyter notebook 在终端启动是可以正常启动的,但是

(这里注释一下,那个报错图片不小心被我删了,但是教程不影响,大家看到了可以去试一试)

在浏览器打开http://127.0.0.1:8888/tree?token=cadf7df6d0cda7b24665d9c4e6fa2de22d10a3b1ef378b89发现浏览器无响应,改成服务器的IP也无响应,终于才找到了以下方法

配置远程访问

首先,我们原先就已经安装好了jupyter,我们现在需要配置远程访问

生成配置文件
jupyter notebook --generate-config 这将在 ~/.jupyter/ 目录下生成 jupyter_notebook_config.py 文件。

设置密码
jupyter notebook password 输入的密码会保存到 .jupyter/jupyter_notebook_config.json 文件中。

修改配置文件
打开 jupyter_notebook_config.py 文件,添加以下几行:

c.NotebookApp.ip = '*' # 允许所有IP访问 c.NotebookApp.open_browser = False # 不打开浏览器 c.NotebookApp.port = 8888 # 设置端口

这样,你可以通过服务器的IP地址和端口号在浏览器中访问Jupyter

启动Jupyter

在服务器上运行以下命令启动Jupyter:

jupyter notebook --no-browser --port=8888 --ip=0.0.0.0

然后在本地机器上通过SSH隧道转发端口:

ssh -N -f -L localhost:8888:localhost:8888 user@server_ip

在浏览器中输入http://localhost:8888 即可访问Jupyter

English

Introduction

Originally, I wanted to set up remote development using PyCharm Pro, but suddenly realized that running jupyter notebook from the terminal worked fine, but when opening http://127.0.0.1:8888/tree?token=cadf7df6d0cda7b24665d9c4e6fa2de22d10a3b1ef378b89 in the browser, I noticed that the browser was unresponsive and the server IP also wouldn't work. Finally, I found a solution.

Configuring Remote Access

First, we had already installed Jupyter notebook when setting up PyCharm Pro. Now, we need to configure remote access.

Generating Configuration File
We generate a configuration file using jupyter notebook --generate-config which will be created in the ~/.jupyter/ directory.

Setting Password
We set a password for Jupyter using the command jupyter notebook password, and this password is saved in .jupyter/jupyter_notebook_config.json.

Modifying Configuration File
Open the jupyter_notebook_config.py file, and add the following lines:

c.NotebookApp.ip = '*'  # Allows all IP addresses to access c.NotebookApp.open_browser = False  # Does not open the browser c.NotebookApp.port = 8888  # Sets the port

With this configuration, you can access Jupyter by entering the server's IP address and port in the browser.

Starting Jupyter

On the server, we start Jupyter with the following command:

jupyter notebook --no-browser --port=8888 --ip=0.0.0.0

Then, on the local machine, we use SSH to forward the port:

ssh -N -f -L localhost:8888:localhost:8888 user@server_ip

In the browser, you can access Jupyter by entering http://localhost:8888.