树莓派4+python3.7+pytorch+opencv+jupyternotebook

tech2022-07-12  192

python安装

卸载原来的2.7、3.5、3.7

sudo apt-get autoremove python2.7 python3.5 python 3.7

重装3.7

sudo apt-get install python3.7 sudo rm /usr/bin/python sudo ln -s /usr/bin/python3.7 /usr/bin/python

重装pip3

wget https://bootstrap.pypa.io/get-pip.py sudo python3.7 ./get-pip.py

重新安装numpy

到https://www.piwheels.org/simple/numpy/

下载numpy-1.17.2-cp37-cp37m-linux_armv7l.whl

卸载原来的numpy

sudo pip3 uninstall numpy

到目录路径下安装numpy

pip3 install numpy-1.17.2-cp37-cp37m-linux_armv7l.whl

测试

进入python,import numpy

安装pytorch

安装torch

pip3 install torch-1.3.0a0+de394b6-cp37-cp37m-linux_armv7l.whl --user

安装torchvision

pip3 install torchvision-0.4.1a0+a263704-cp37-cp37m-linux_armv7l.whl --user

安装opencv

安装依赖

sudo apt-get install libatlas-base-dev sudo apt-get install libjasper-dev sudo apt-get install libqtgui4 sudo apt-get install libqt4-test sudo apt-get install libhdf5-dev

到https://www.piwheels.org/simple/opencv-contrib-python/

下载opencv_contrib_python-4.0.1.24-cp37-cp37m-linux_armv7l.whl

到目录下安装opencv

pip3 install opencv_contrib_python-4.0.1.24-cp37-cp37m-linux_armv7l.whl

测试

import torch import torchvision import cv2

安装jupyternotebook

1)下载安装

sudo apt install jupyter

2)测试

jupyter noyebook

通过网页访问,测试import torch是否可以成功。

3)配置远程访问

生成密码

python3.5 >>from notebook.auth import passwd >>passwd() #输入密码后得到生成的密文,复制密文

生成配置文件

jupyter notebook --generate-config #生成默认配置文件

修改配置文件

vi ~/.jupyter/jupyter_notebook_config.py #打开上一步生成的配置文件,修改下面几行内容 c.NotebookApp.password = 'sha1:<your-sha1-hash-value>' #刚生成的密码 c.NotebookApp.port = 8888 #内部访问端口 c.NotebookApp.ip = '0.0.0.0' c.NotebookApp.open_browser = False c.NotebookApp.allow_remote_access = True c.NotebookApp.notebook_dir = '/home/pi/web_notebooks' #可选

notebook为5.6.0以下版本,c.NotebookApp.ip = '*',为5.7.0,则设置为c.NotebookApp.ip = '0.0.0.0'

配置开机启动

sudo nano /home/pi/.bashrc

增加开机启动脚本

nohup jupyter notebook&
最新回复(0)