Raspberry pi 树莓派安装 Jupyter lab

使用Jupyter lab进行python开发是非常快捷友好的方式。

其特点:

所写即所得即所见

调试方便

本文就主要介绍,怎么在树莓派上安装Jupyter lab。


安装jupyter lab

在终端输入以下命令:

pip3 install jupyterlab

如果网络慢可以试试使用其他源的方法,例如以下命令进行安装:

pip3 install jupyterlab -i https://pypi.tuna.tsinghua.edu.cn/simple

创建配置文件

在终端输入以下命令:

jupyter notebook --generate-config

or

jupyter-lab --generate-config

之后会输出,创建的文件详细位置,请记住这个位置。要记得,很重要。


设置局域网能访问Jupyter lab

使用nano修改配置文件,也就是之前生成的(配置文件路径,请使用你对应的路径做修改)

在终端输入以下命令:

nano  /home/pi/.jupyter/jupyter_notebook_config.py

找到以下配置项,去掉行首的#,并且修改为如下即可:

  • c.NotebookApp.allow_origin = ‘*’ #allow all origins
  • c.NotebookApp.ip = ‘0.0.0.0’ # listen on all IPs

保存退出


设置Jupyter lab的访问密码

在终端输入命令:

jupyter notebook password`

此时,会要求你输入密码,输入后回车即可

(注意:在输入密码的状态下,键盘按下字符是没有任何显示的,这是正常现象,继续输入最后回车即可)

例如我在这里输入密码为:makeronstie


重启树莓派

在命令行输入以下命令即可:

sudo reboot

启动jupyter lab

在命令行输入以下命令即可:

jupyter-lab

现在,

在本地访问 http://127.0.0.1:8888

或者

在局域网中的机器访问 http://your-ip-address:8888

即可打开,

然后输入你设置的密码,

就能在网页上操作你的树莓派和开发python程序。

可能遇到的问题

arm-linux-gnueabihf-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DFFI_BUILDING=1 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.10 -c c/_cffi_backend.c -o build/temp.linux-armv7l-3.10/c/_cffi_backend.o
            c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
               15 | #include <ffi.h>
                  |          ^~~~~~~
            compilation terminated.
            error: command '/usr/bin/arm-linux-gnueabihf-gcc' failed with exit code 1
            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
      error: legacy-install-failure

      × Encountered error while trying to install package.
      ╰─> cffi

      note: This is an issue with the package mentioned above, not pip.
      hint: See above for output from the failure.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

安装 libffi-dev 解决 ffi.h 报错的问题

apt install libffi-dev
arm-linux-gnueabihf-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DFFI_BUILDING=1 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.10 -c c/_cffi_backend.c -o build/temp.linux-armv7l-3.10/c/_cffi_backend.o
            c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
               15 | #include <ffi.h>
                  |          ^~~~~~~
            compilation terminated.
            error: command '/usr/bin/arm-linux-gnueabihf-gcc' failed with exit code 1
            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
      error: legacy-install-failure

      × Encountered error while trying to install package.
      ╰─> cffi

      note: This is an issue with the package mentioned above, not pip.
      hint: See above for output from the failure.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

Install libffi-dev to fix this issue.

apt install libffi-dev