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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章