欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

怎样在服务器部署Jupyter Notebook

程序员文章站 2022-06-26 15:14:17
立下 Flag 要写本书,名字还没想好,大致的内容就是使用 Python 语言学算法之类的。由于工作的原因,不可能将代码啥的保存在一台电脑上,再加上截图风格要统一,所以决定,用 Jupyter 作为代码测试、运行环境。我有自己的服务器,所以就把 Jupiter 部署在上面吧!记录下过程。安装 Jupyter notebooksudo pip3 install ipythonsudo pip3 install jupyter创建 Jupyter notebook 工作目录sudo mkdir j...

立下 Flag 要写本书,名字还没想好,大致的内容就是使用 Python 语言学算法之类的。由于工作的原因,不可能将代码啥的保存在一台电脑上,再加上截图风格要统一,所以决定,用 Jupyter 作为代码测试、运行环境。
我有自己的服务器,所以就把 Jupiter 部署在上面吧!记录下过程。

安装 Jupyter notebook

sudo pip3 install ipython
sudo pip3 install jupyter

创建 Jupyter notebook 工作目录

sudo mkdir jupyter_notebook

生成配置文件

jupyter-notebook --generate-config
OTP:Writing default config to: /home/ubuntu/.jupyter/jupyter_notebook_config.py

生成密码

Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from notebook.auth import passwd
>>> passwd()
Enter password: 
Verify password: 
'argon2:$argon2id$v=19$m=10240,t=10,p=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
>>> exit()

修改配置文件

vim .jupyter/jupyter_notebook_config.py

在jupyter_notebook_config.py中最下面添加一下配置

c.NotebookApp.ip='*' # *代表所有机器都可访问,或者输入服务ip
c.NotebookApp.password = u'sha1:......' # 把引号中的内容替换为刚刚生成的sha1开头的密码
c.NotebookApp.notebook_dir = u'/root/jupyter_/home/ubuntu/jupyter_notebook # 第一步创建的工作目录
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.allow_root = True
:wq 保存退出

修改密码并启动服务

由于上面生成的密码太长,所以修改一个简单的密码

jupyter notebook password

输入2次新密码

ubuntu@VM-0-3-ubuntu:~$ jupyter notebook password
Enter password: 
Verify password: 
[NotebookPasswordApp] Wrote hashed password to /home/ubuntu/.jupyter/jupyter_notebook_config.json

为了使密码生效,防止jupyter notebook不允许以root方式启动,我们需要在首次访问需要加入参数

nohup jupyter-notebook --allow-root --config=/root/.jupyter/jupyter_notebook_config.py &

第二次启动就不用–config这个参数了

nohup jupyter-notebook --allow-root &

启动即可
怎样在服务器部署Jupyter Notebook
怎样在服务器部署Jupyter Notebook

本文地址:https://blog.csdn.net/qq_34307082/article/details/110425367