这可能有点晚了,但可以在 Pi 上安装 Jupyter 并直接从 Mac 上的浏览器进行开发。
如果您有 Pi 2 或 3(或其他包含 ARM7 的设备),您可以安装 Miniconda:
https://gist.github.com/simoncos/a7ce35babeaf73f512be24135c0fbafb
如果您希望安装适用于 Python 2 的 Miniconda,则将其简称为“Miniconda-latest-Linux-arm7l.sh”。
还有一个名为 Berryconda 的版本似乎支持早期的 ARM6 风格的 Pi:
https://github.com/jjhelmus/berryconda
我为我的 Pi3 选择了 miniconda 路线,但对于 Pi Zero,我坚持使用系统 python 和对 pip 和 pip3 的大量调用。
两种方式都完成了,我想我更喜欢依赖系统蟒蛇。尤其是专用于设备(而不是将其视为通用开发机器)。 Miniconda 已经足够精简,并且 ARM 支持也足够稀疏,我发现即使在 miniconda 环境中我也需要 pip 很多包。唯一真正的好处是能够删除整个 miniconda 树并开始清理,但如果我要这样做,我可能会重新启动整个操作系统。
您可以从这里开始安装 Jupyter:
http://jupyter.org/install
您可以在 Pi 上为 Jupyter 打开 HTTP 端口并通过本地网络访问它,或者您可以使用以下方式通过 SSH 隧道进入:
ssh -L 8001:localhost:8888 raspberrypi.local
我更喜欢的方式是安装jupyterhub:
https://github.com/jupyterhub/jupyterhub
这很简单,一个问题是您需要使用 SSL 来保护连接,这可能意味着自签名证书类似于:
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout jupyterhub.key -out
问题在于 Safari 对自签名证书感到窒息。您需要在钥匙串中信任它:
https://support.apple.com/kb/PH25443?locale=en_US&viewlocale=en_US
您可以通过单击“访问站点”来暂时绕过问题的Safari,但长期的解决方案是单击其他选项,查看证书,将其拖到桌面,在钥匙串中打开它,然后信任它。
你会想要通过 jupyterhub 配置,但有两个选项对我来说并不明显,但它们很有用:
c.JupyterHub.cookie_secret_file = '/srv/jupyterhub/jupyterhub_cookie_secret'
c.JupyterHub.db_url = '/srv/jupyterhub/jupyterhub.sqlite'
根据您的喜好设置这些路径,但它们会让您免于在启动 jupyterhub 的任何目录中创建文件。
将 jupyterhub 设置为在启动时启动也可能很有用:
#setup jupyterhub to launch at boot
create /etc/systemd/system/jupyterhub.service:
[Unit]
Description=Jupyterhub
After=syslog.target network.target
[Service]
User=root
Environment="PATH=/opt/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ExecStart=/opt/miniconda3/bin/jupyterhub -f /etc/jupyterhub/jupyterhub_config.py
[Install]
WantedBy=multi-user.target
sudo systemctl enable jupyterhub
最后,jupyterlab 也可以:
http://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html
http://jupyterlab.readthedocs.io/en/stable/user/jupyterhub.html
设置完成后,您可以像在本地计算机上一样在 Jupyter 中进行开发。它还使您可以从浏览器中访问终端。
如果您四处寻找,还有一些方法可以设置您的 Pi,使其显示在 Finder 的文件共享中,并允许您从本地 MacOS 屏幕共享进行 VNC。
你没有特别要求这个,但如果你正在做相机工作,那么安装 OpenCV 是值得的。这应该让你大部分时间。它假设 miniconda 安装在 /opt/miniconda3 中并包含为 python3 构建 OpenCV 的标志:
#install opencv
#https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html
#note: some optional packages not installed
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev
sudo apt-get install cmake-curses-gui
sudo apt-get install libopenexr-dev
#from the OpenCV source directory
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_opencv_python3=yes \
-D PYTHON3_INCLUDE_DIR=/opt/miniconda3/include/python3.4m \
-D PYTHON3_LIBRARY=/opt/miniconda3/lib/libpython3.4m.so \
-D PYTHON3_PACKAGES_PATH=/opt/miniconda3/lib/python3.4/site-packages \
..
make -j4
#this might take more than one attempt, for some reason it crashed the first time through, but succeeded the second
sudo make install