Install jupyter notebook on the server side and configure one-stop service for local use and environment [run ipynb on the server]

1. Generate a configuration file:

jupyter notebook --generate-config

The path is ~/.jupyter/jupyter_notebook_config.py

2. Configure Jupyter notebook password

ipython
from notebook.auth import passwd
passwd()  #自定义密码,会提示输入两次,这个密码就是本地登录浏览器的密码

The above code generates a key, remember that key.

3, modify the configuration file ~/.jupyter/jupyter_notebook_config.py

vim ~/.jupyter/jupyter_notebook_config.py
# 或者用pycharm直接打开在本地修改也行

After opening the configuration file, shift+g jumps to the end, i enters the edit mode, and inserts the following code:
(I don’t use the last line, you can uncomment it if you need it)

c.NotebookApp.ip='*' #设置访问notebook的ip,*表示所有IP

c.NotebookApp.password = u'sha1:xxx' #填写刚刚复制的密钥 

c.NotebookApp.open_browser = False # 禁止notebook启动时自动打开浏览器

c.NotebookApp.allow_root = True #允许root用户

c.NotebookApp.port =8890 #指定访问的端口,默认是8888。

c.NotebookApp.allow_remote_access = True # 是否允许远程访问

#c.NotebookApp.notebook_dir = '/usr/local/bin/jupyter'  # 设置工作目录

Esc to exit editing, shift + :wq to save

4. Locally access jupyter of the remote server

1. First start the Jupyter notebook on the Linux server

jupyter notebook --no-browser --port=8890

2. Then forward the port locally

ssh -N -f -L localhost:8888:localhost:8890 -p 22 remote_user@remote_host  # 默认端口是22
# remote_user@remote_host: 远程机器(服务器)用户名@服务器IP

like

ssh -N -f -L localhost:8888:localhost:8890 -p 22 [email protected]

Finally, open a browser locally and enter the following:

http://localhost:8888/
或
http://10.10.10.253:8890

Enter the aforementioned custom password for the first login.
insert image description here
Note that http does not have s.

Configure conda environment for jupyter notebook

Download the nb_conda library

conda install nb_conda_kernels

Then restart and run jupyter notebook directly.
If there is a problem:
uninstall jupyter notebook and reinstall it

conda uninstall jupyter
conda install jupyter

It may be necessary to re-download nb_conda_kernels:

conda install nb_conda_kernels

Or:
first activate the corresponding conda environment and then

python -m ipykernel install --user --name 环境名称 --display-name "环境名称"

Reference:
Install jupyter notebook on the linux server and use it locally

Guess you like

Origin blog.csdn.net/qq_45934285/article/details/130935763