zoukankan      html  css  js  c++  java
  • 在树莓派上搭建jupyter notebook server

    自从搬家后,树莓派闲置了好一段时间,最近打算将其利用起来。想来想去,搭个jupyter notebook用要靠谱的,毕竟经常要实验一些Python脚本。
    具体过程参考以下链接:
    https://www.techcoil.com/blog/how-to-setup-jupyter-notebook-on-raspberry-pi-3-with-raspbian-stretch-lite-supervisor-and-virtualenv-to-run-python-3-codes/

    教程中给出了在virtualenv中启动Python3版本的jupyter notebook server的方案,这样做的好处是可以方便地单独管理jupyter的包。在这个教程中,还发现了个人折腾启动服务的神器,supervisor,好评。

    tips: 如果想要让jupyter同时支持Python2和Python3,安装对应的python2-ipykernel即可,此时Python2为/usr/bin/python2

    最后附上,根据教程编写的自动化脚本:

    # 安装supervisor和virtualenv
    apt install supervisor python3-virtualenv -y
    # 在virtualenv中安装jupyter
    python3 -m virtualenv -p python3 /home/pi/jupyter-env
    source /home/pi/jupyter-env/bin/activate
    pip install jupyter
    deactivate
    # 在virtualenv环境中启动jupyter
    mkdir /home/pi/jupyter-notebook
    chmod 777 /home/pi/jupyter-notebook
    # # 设置jupyter启动脚本
    (
    cat << EOF
    #!/bin/bash
    source /home/pi/jupyter-env/bin/activate
    jupyter notebook --ip 0.0.0.0 --port 9999 --no-browser
    deactivate
    EOF
    ) > /home/pi/jupyter-notebook/run-jupyter-notebook.sh
    sudo chmod +x /home/pi/jupyter-notebook/run-jupyter-notebook.sh
    # supervisor配置
    (
    cat << EOF
    #!/bin/bash
    [program:jupyter-notebook]
    directory=/home/pi/jupyter-notebook
    command=/bin/bash -E -c ./run-jupyter-notebook.sh
    autostart=true
    autorestart=true
    stopsignal=INT
    stopasgroup=true
    killasgroup=true
    user=pi
    EOF
    ) > /etc/supervisor/conf.d/jupyter-notebook.conf
    # 重启supervisor以启动jupyter notebook
    systemctl restart supervisor.service
    sleep 5
    # 输出用于登录验证的token
    supervisorctl tail jupyter-notebook stdout
    
  • 相关阅读:
    洛谷 P1767 家族_NOI导刊2010普及(10)
    洛谷 P2919 [USACO08NOV]守护农场Guarding the Farm
    COGS 1619. [HEOI2012]采花
    UVA 11181 Probability|Given
    hdu 3336 Count the string
    洛谷 P2176 [USACO14FEB]路障Roadblock
    洛谷 P2691 逃离
    BZOJ 1040: [ZJOI2008]骑士
    vijos 1320 清点人数
    POJ 3417 Network
  • 原文地址:https://www.cnblogs.com/carlsplace/p/9694469.html
Copyright © 2011-2022 走看看