tmux+jupyter-notebook后台保存python运行空间

1. jupyter-notebook安装

Project Jupyter | Installing Jupyter

install

创建一个新的环境用于jupyter notebook运行:conda create -n jupyter python
按照官方教程安装jupyter即可。

2. jupyter notebook配置

对jupyter进行一定的配置可以方便我们使用,尤其是远程访问服务器。
主要参考博客:【随记】服务器安装并配置jupyter notebook,并使用vscode扩展进行连接 - 氢离子活度指数 - 博客园

2.1 在python中设定passwd

from jupyter_server.auth import passwd
passwd()
#然后会让你输出密码,确认密码,以及返回密钥数据,备份返回的密钥信息。

2.2 创建jupyter配置文件

运行jupyter notebook --generate-config生成jupyter环境配置文件(默认在~/.jupyter/jupyter_notebook_config.py,同目录下json文件是密钥hash)

2.3 修改jupyter环境配置文件中以下配置项

c.ServerApp.ip='0.0.0.0'
c.ServerApp.password=u'sha1****' #就之前保存的验证密码
c.ServerApp.open_browser =False # 设置是否自动打开浏览器
c.ServerApp.port =8889  # 设置端口
c.ServerApp.allow_remote_access = True
c.ServerApp.root_dir = 'xxxxxxx' # 配置默认访问的目录

2.4 启动jupyter服务

即用即启,占用一个shell,用后关闭:jupyter notebook --allow-root

2.5 vscode中使用(暂时还没有配置)

待续

3. tmux中运行jupyter notebook

conda install -c conda-forge tmux
tmux new -s jp
jupyter notebook --allow-root
 #http://Phenix:8889/tree

复制url到浏览器即可。如果按照步骤2准确配置了jupyter,那么无需输入密码即可进入。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容