一、远程连接
首先在服务器端安装Jupyter Notebook并通过配置文件进行相应参数的设置,然后使用本地主机的浏览器远程访问。
参考博客:https://my.oschina.net/u/4218785/blog/3142148
1.安装
conda activate abc #激活虚拟环境
pip install jupyter #安装
jupyter notebook --generate-config #生成配置文件
备注:配置文件的所在路径一般为 ~/.jupyter/jupyter_notebook_config.py
注意:如果之前安装过,可能会提示你是否要重置配置文件,建议不要!(输入n)例如本机上重置可能会导致jupyter notebook无法正常在浏览器打开
2.生成密文
from IPython.lib import passwd
passwd()
3.修改默认配置文件
vim ~/.jupyter/jupyter_notebook_config.py
文件内容如下:
c.NotebookApp.ip='*'
c.NotebookApp.password = u'sha1:xxxxxxxxxxx(上一步生成的密文)'
c.NotebookApp.port = 9999 #随便指定一个闲置端口
c.NotebookApp.open_browser = False #禁止自动打开浏览器
c.NotebookApp.allow_remote_access = True #远程访问
c.NotebookApp.allow_root = True
c.NotebookApp.notebook_dir = '/home/user/myr' #设置根目录,限制访问
4.运行
jupyter notebook
5.多用户连接配置
cp ~/.jupyter/jupyter_notebook_config.py ~/.jupyter/jpconfig.py
vim ~/.jupyter/jpconfig.py #修改配置的端口号
jupyter notebook --config ~/.jupyter/jpconfig.py #指定使用的配置文件
参考博客:https://blog.csdn.net/qq_18506419/article/details/103915423
6.远程访问
在本地主机上打开浏览器,地址栏输入
服务器IP:端口号
10.10.10.10:9999
7.若配置完成后,在本地浏览器中无法访问服务器
在本地主机上的shell(Eg.使用MobaXterm新建shell)输入
ssh -p remote_port remote_user@remote_ip -L127.0.0.1:1234:127.0.0.1:服务器jupyter notebook的端口
#remote_user@remote_ip 用实际的远程帐户和远程地址替换
#1234可改为1024-65535之间尚未使用的端口号
#-L表示本地映射转发
在本地主机上打开浏览器,地址栏输入 127.0.0.1:1234 即可远程访问
参考博客:
https://www.jianshu.com/p/2fc5545901c7
https://blog.csdn.net/CZ505632696/article/details/79604446
二、切换虚拟环境
参考博客:https://blog.csdn.net/u014264373/article/details/86541767
conda activate abc #激活虚拟环境
conda install ipykernel
python -m ipykernel install --user --name abc --display-name "Python3 abc" #将选择的conda环境注入Jupyter Notebook
打开Jupyter Notebook,顶部菜单栏选择Kernel–Change kernel–Python3 abc
如果报错ImportError: cannot import name ‘generator_to_async_generator’
pip uninstall -y ipython prompt_toolkit
pip install ipython prompt_toolkit
参考博客:https://blog.csdn.net/u011331731/article/details/88310809