-Forest- 发表于 2020-4-20 11:09:03

rk3399ubuntu18.04 pytorch环境搭建

本帖最后由 -Forest- 于 2020-4-22 17:41 编辑

整整配置了一个周末,把踩过的坑记录下来,以后参考用:
1.换源:
sudo vi /etc/apt/sources.lis备份旧源以防万一
替换为下列内容#deb http://ports.ubuntu.com/ bionic main restricted universe multiverse
#deb-src http://ports.ubuntu.com/ bionic main restricted universe multiverse
#deb http://ports.ubuntu.com/ bionic-updates main restricted universe multiverse
#deb-src http://ports.ubuntu.com/ bionic-updates main restricted universe multiverse
#deb http://ports.ubuntu.com/ bionic-security main restricted universe multiverse
#deb-src http://ports.ubuntu.com/ bionic-security main restricted universe multiverse
#deb http://ports.ubuntu.com/ bionic-backports main restricted universe multiverse
#deb-src http://ports.ubuntu.com/ bionic-backports main restricted universe multiverse
#deb http://ports.ubuntu.com/ubuntu-ports/ bionic main universe restricted
#deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic main universe restricted #Added by software-properties

deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic main universe restricted
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic main universe restricted

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main universe restricted
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main universe restricted

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
更新源
apt-get update
2.更改python默认版本
新系统默认2.7,更换为系统自带3.6
rm /usr/bin/python
ln -s /usr/bin/python3.6 /usr/bin/python
查看是否替换成功
python -V
3.安装环境
sudo apt-get update

sudo apt-get upgarde#这条不用
sudo apt-get install python-pip python-dev build-essential

sudo apt-get install python3-pip python3-dev build-essential

sudo apt-get install gedit

sudo apt-get install openssl*

sudo apt-get install ipython3

sudo apt-get install minicom

sudo apt-get install cmake git

sudo apt-get install inetutils-ping

安装中文库和输入法:可选

sudo apt-get install scim scim-pinyin

安装火狐浏览器:可选

sudo apt-get install firefox

安装依赖:


sudo apt-get install python3-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

sudo apt-get install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

apt-get install python3-dev python3-pip
5 安装opencv
apt search opencv可以看到python-opencv和python3-opencv。分别对应python2和python3的版本。
安装python3的版本
apt-get install python3-opencv这个命令自动安装numpy
如果不成功可以自己编译opencv,比较麻烦,后续上传opencv源码和编译方法:opencv源码:
提取码:92oj
编译参考:
https://blog.csdn.net/qq_25680531/article/details/80854344
5 安装PyTorch

如果不想自己折腾,直接下载编译好的包安装即可
百度网盘:
提取码:fxf8
下载好后:
pip3 install ./torch-1.1.0a0+7e73783-cp36-cp36m-linux_aarch64.whl装好后 导入torch时会报错:
File "/home/firefly/.local/lib/python3.6/site-packages/torch/__init__.py", line 79, in <module>
    from torch._C import *
ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory
原因是缺少库:libopenblas.so
安装参考:https://blog.csdn.net/mywmy/article/details/96993537


如果想试一下编译pytorch:
pytorch1.1.0源码下载:(如果不需要新版本,网速慢就直接下载这个)
提取码:cvew
pytorch源码编译参考树莓派上编译安装pytorch
交换空间尽量在2g以上,要不内存实在不够用,编译六核全开老报错,我用三个核编译。




{:4_114:}
然后就能愉快的跑模型了












Wanggp 发表于 2020-4-22 00:57:31

你好,我按照你的方法安装了pytroch,但是安装完成之后出现了这个请问题,请问你有出现过么?
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/firefly/.local/lib/python3.6/site-packages/torch/__init__.py", line 79, in <module>
    from torch._C import *
ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory

-Forest- 发表于 2020-4-22 09:50:12

本帖最后由 -Forest- 于 2020-4-22 09:52 编辑

Wanggp 发表于 2020-4-22 00:57
你好,我按照你的方法安装了pytroch,但是安装完成之后出现了这个请问题,请问你有出现过么?
>>> import...
重新打开一个终端试一试,或者重启一下。装一下openblas

LiCheng 发表于 2020-4-22 10:00:04

感谢楼主分享。

-Forest- 发表于 2020-4-22 10:07:31

LiCheng 发表于 2020-4-22 10:00
感谢楼主分享。

大佬入场{:4_127:}

九虎 发表于 2020-4-22 15:22:10

楼主你好,你的帖子对我帮助很大。但是我现在需要用1.4.0版本的torch,我在官网上找了个版本torch-1.4.0-cp36-cp36m-manylinux1_x86_64.whl是不是不能使用?我要升到1.4.0的版本是不是需要自己完成编译?

-Forest- 发表于 2020-4-22 17:24:29

九虎 发表于 2020-4-22 15:22
楼主你好,你的帖子对我帮助很大。但是我现在需要用1.4.0版本的torch,我在官网上找了个版本torch-1.4.0-cp ...

你这个wheel是x86_64端的,不是arm下的,如果非要用1.4.0的话就得自己去编译。

Wanggp 发表于 2020-4-22 22:06:03

-Forest- 发表于 2020-4-22 09:50
重新打开一个终端试一试,或者重启一下。装一下openblas

谢谢楼主,这个问题已经解决了,请问这个roc-rk3399-pc在跑深度学习的模型的时候有没有加速电路?pytorch是不是只能用cpu计算。

wx_哄哄_Xy8yy 发表于 2020-4-22 23:01:30

楼主,用你的方法已经成功安装上torch了,但是我torchvision怎么也装不上,能不能详细讲解下torchvision怎么安装,谢谢楼主。

-Forest- 发表于 2020-4-23 21:18:06

wx_哄哄_Xy8yy 发表于 2020-4-22 23:01
楼主,用你的方法已经成功安装上torch了,但是我torchvision怎么也装不上,能不能详细讲解下torchvision怎 ...

我一开始装torchvision也装不上,装好pytorch后自己就装上了,试试再装一遍pytorch。实在不行自己编译一下源码。
页: [1] 2
查看完整版本: rk3399ubuntu18.04 pytorch环境搭建