Jupyter_notebook 搭建服务及更换主题

Jupyter notebook

准备工作

  1. 一台云服务器(我用的是腾讯服务器,centos7)
  2. 服务器已安装 python3
  3. 有一定python基础
  4. 热爱学习的心和不怕艰辛的热忱

安装jupyter-notebook

  1. pip3 install jupyter notebook
  2. 生成配置jupyter notebook --generate-config
  3. 配置一般在 ~/.jupyter/jupyter_notebook_config.py
  4. 设置密码及设置工作目录
    ## The directory to use for notebooks and kernels.
    c.NotebookApp.notebook_dir = '/root/jupyter_notebooks'
    
    ## Whether to open in a browser after starting. The specific browser used is
    ...
    #  To generate, type in a python/IPython shell:
    #
    #    from notebook.auth import passwd; passwd()
    #
    #  The string should be of the form type:salt:hashed-password.
    c.NotebookApp.password = 'sha1:ff737af759e0:5fdc6a7df25b9af4912204ced9ca309336defe8f'
    
    1. 修改密码,使用python生成密码的密钥
      	from notebook.auth import passwd; print(passwd("123456"))
      
    2. 生成密码后,替换掉那一串字符
  5. 启动服务
    # 正常启动(前台运行)
    $ jupyte-notebook --config ~/.jupyter/jupyter_notebook_config.py
    # 后台运行
    $ mkdir jupyter_notebooks
    $ nohup jupyter-notebook --config .jupyter/jupyter_notebook_config.py 1>jupyter_notebooks/jupyter.log 2>&1 &
    
  6. 测试是否成功
    $wget 127.0.0.1:8888
    --2020-01-11 10:49:58--  http://127.0.0.1:8888/
    Connecting to 127.0.0.1:8888... connected.
    HTTP request sent, awaiting response... 302 Found
    Location: /tree? [following]
    --2020-01-11 10:49:58--  http://127.0.0.1:8888/tree?
    Reusing existing connection to 127.0.0.1:8888.
    HTTP request sent, awaiting response... 302 Found
    Location: /login?next=%2Ftree%3F [following]
    --2020-01-11 10:49:58--  http://127.0.0.1:8888/login?next=%2Ftree%3F
    Reusing existing connection to 127.0.0.1:8888.
    HTTP request sent, awaiting response... 200 OK
    Length: 9113 (8.9K) [text/html]
    Saving to: ‘index.html’
    
    100%[===================================================================>] 9,113       --.-K/s   in 0s
    2020-01-11 10:49:58 (208 MB/s) - ‘index.html’ saved [9113/9113]
    
  7. 设置防火墙通过8888端口
    iptables -A INPUT -p tcp -m tcp --dport 8080 -j accept
    or
    firewall-cmd --permanent --add-port=8888/tcp
    firewall-cmd --reload
  8. 打开浏览器,访问http://ip:8888

常见问题

  • 密码修改不成功
  1. ./jupyter 下面还有一个 jupyter_notebook_config.json,将其删除,然后修改配置文件,最后重启服务就可以了
  • 浏览器打开没反应怎么办
  1. 先看下电脑和云服务器的网络是否通畅 ping ip
  2. 再看下云服务器的jupyter进程是否还在 ps -aux | grep jupyterlsof -i:8888
  3. 看下端口是否能telnet telnet ip 8888 电脑没有telnet怎么办
  4. 看下防火墙是否已经通过 8888 端口,云服务除linux防火墙外,云服务商还有一套防火墙,可以自己询问相应的客服咨询

Jupyter notebook 修改字体,修改颜色,修改主题

  1. 感谢大神做的notebook主题,查看GitHub
  2. 安装jupyter themes
    pip3 install --upgrade jupyterthemes
  3. 使用命令行设置相应配置
    1. 查看支持的主题
      $ jt -l
      Available Themes:   chesterish   grade3
      gruvboxd
      gruvboxl
      monokai
      oceans16
      onedork
      solarizedd
      solarizedl
      	```
      
    2. 配置 主题为 oceans16, 字体为 fira,字体大小为 13
      	jt -t oceans16 -f fira -fs 13
      
    3. 具体规则
      在这里插入图片描述
  4. 参考文章: https://blog.csdn.net/qq_30565883/article/details/79444750
  5. 所有字体
  6. 注意事项:直接修改字体和字体大小,是不会生效的
  7. 清除所有主题,恢复默认 jt -r
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章