美文网首页
Run Jupyter notebook remotely

Run Jupyter notebook remotely

作者: 不到15不改名 | 来源:发表于2019-07-04 20:27 被阅读0次

    1. 安装Anaconda

    省略

    2. 生成配置文件

    $ jupyter notebook --generate-config
    

    默认配置文件的位置

    Windows: C:\Users\USERNAME\.jupyter\jupyter_notebook_config.py
    OS X: /Users/USERNAME/.jupyter/jupyter_notebook_config.py
    Linux: /home/USERNAME/.jupyter/jupyter_notebook_config.py
    

    3. 设置jupyter密码

    $ jupyter notebook password
    Enter password:  ****
    Verify password: ****
    [NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json
    

    哈希密码默认在~/.jupyter/jupyter_notebook_config.json

    4. 用SSL加密通讯

    生成加密证书

    $ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem
    

    编辑配置文件~/.jupyter/jupyter_notebook_config.py

    # Set options for certfile, ip, password, and toggle off
    # browser auto-opening
    c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
    c.NotebookApp.keyfile = u'/absolute/path/to/your/certificate/mykey.key'
    # Set ip to '*' to bind on all interfaces (ips) for the public server
    c.NotebookApp.ip = '*'
    c.NotebookApp.password = u'sha1:bcd259ccf...<your hashed password here>'
    c.NotebookApp.open_browser = False
    
    # It is a good idea to set a known, fixed port for server access
    c.NotebookApp.port = 9999
    

    好像是由于jupyter的版本原因,启动会出一个ValueError: '' does not appear to be an IPv4 or IPv6 address这样的错,把c.NotebookApp.ip = '*'里面的*换成0.0.0.0 work for me (见参考2)

    5. 后台启动

    $ nohup jupyter lab &
    

    然后就可以本地通过浏览器打开(要用https不是http),记得加你设置的端口号(e.g., https://server_address:9999


    Rerefences

    1. Jupyter Notebook官方文档:https://jupyter-notebook.readthedocs.io/en/stable/public_server.html
    2. StackOverflow:https://github.com/jupyter/notebook/issues/3946

    版本信息

    Linux版本

    NAME="CentOS Linux"
    VERSION="7 (Core)"
    ID="centos"
    ID_LIKE="rhel fedora"
    VERSION_ID="7"
    PRETTY_NAME="CentOS Linux 7 (Core)"
    ANSI_COLOR="0;31"
    CPE_NAME="cpe:/o:centos:centos:7"
    HOME_URL="https://www.centos.org/"
    BUG_REPORT_URL="https://bugs.centos.org/"
    
    CENTOS_MANTISBT_PROJECT="CentOS-7"
    CENTOS_MANTISBT_PROJECT_VERSION="7"
    REDHAT_SUPPORT_PRODUCT="centos"
    REDHAT_SUPPORT_PRODUCT_VERSION="7"
    

    Anaconda版本

         active environment : base
        active env location : /home/xiangjie/programs/anaconda3
                shell level : 1
           user config file : /home/xiangjie/.condarc
     populated config files : 
              conda version : 4.6.11
        conda-build version : 3.17.8
             python version : 3.7.3.final.0
           base environment : /home/xiangjie/programs/anaconda3  (writable)
               channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                              https://repo.anaconda.com/pkgs/main/noarch
                              https://repo.anaconda.com/pkgs/free/linux-64
                              https://repo.anaconda.com/pkgs/free/noarch
                              https://repo.anaconda.com/pkgs/r/linux-64
                              https://repo.anaconda.com/pkgs/r/noarch
              package cache : /home/xiangjie/programs/anaconda3/pkgs
                              /home/xiangjie/.conda/pkgs
           envs directories : /home/xiangjie/programs/anaconda3/envs
                              /home/xiangjie/.conda/envs
                   platform : linux-64
                 user-agent : conda/4.6.11 requests/2.21.0 CPython/3.7.3 Linux/3.10.0-862.11.6.el7.x86_64 centos/7.5.1804 glibc/2.17
                    UID:GID : 1063:500
                 netrc file : None
               offline mode : False
    

    相关文章

      网友评论

          本文标题:Run Jupyter notebook remotely

          本文链接:https://www.haomeiwen.com/subject/kvxdhctx.html