在樹莓派上搭建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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM