树莓派4B 安装 Tensorflow 1.13.1 保姆级教程

本文介绍了在树莓派上安装Python3.7.3和Tensorflow1.13.1的步骤,包括系统烧录、使用Mobaxterm远程连接、安装Xrdp远程桌面,以及解决protobuf、_ctypes、OpenSSL等依赖问题和h5py缺失的解决方案。
摘要由CSDN通过智能技术生成

目录

前排感谢

下载系统烧录工具

使用Mobaxterm连接树莓派

 安装远程桌面Xrdp

安装Python3.7.3

安装Tensorflow 1.13.1

我遇到的问题及解决方案

问题1:protobuf版本错误

问题2:No module name '_ctypes'

问题3:OpenSSL

问题4:缺失h5py

问题5:无法导入libhdfs.so


前排感谢

感谢juelianhuayao星宇笔记对本篇文章的部分内容支持

下载系统烧录工具

 此处我选择的是Download for Windows,继续下一步

  • 双击下载好的烧录工具,进行安装(无需操作,傻瓜式自动安装)
  • 在菜单栏中找到Raspberry Pi,点开Raspberry Pi Imager

  • 打开时这个界面,我们先将SD卡连接读卡器,插入电脑USB

  •  点击“选择操作系统”,选择你需要的系统,程序会联网下载,此处我选择32位带桌面的树莓派原始系统

  • 点击“选择SD卡”

  • 点击齿轮按钮,对系统做预先设置
    • 开启SSH服务:默认勾选即可,选择使用密码登录
    • 选择Set username and password,配置登录的账户和密码(从新版开始,需用户自行配置)
    • 开启配置WIFI:输入局域无线网的热点名称和密码,树莓派会在启动后自动联网
    • 开启语言设置:时区选择Asia/Shanghai,键盘布局选择us
    • 永久设置:三个都勾选上

  • 设置配置完成,点击烧录,等待片刻,即可完成系统烧录

使用Mobaxterm连接树莓派

  • 打开连接下载Mobaxterm:点击下载
  • 快捷键Win+R打开运行窗口,输入cmd

  •  输入命令:ping raspberry.local 获得树莓派在局域网中的IP地址
  • 打开Mobaxterm,选择Session,输入获得的IP地址,点击连接,输入账户密码即可连接成功

 安装远程桌面Xrdp

 此部分原文来自星宇笔记,如遇到问题可查看原文修正

  • 换清华源
sudo nano /etc/apt/sources.list

# 将原始内容注释掉,新增如下两行
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib

添加完成后摁快捷键Ctrl + O,保存文件,记得回车确认,随后 Ctrl + X 退出

  • 同样方法替换raspi.list文件中内容
# 命令行输入
sudo nano /etc/apt/sources.list.d/raspi.list 

# 文件中注释原有内容,新增如下内容:
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui
  • pip换源

sudo nano /etc/pip.conf

# 补充下面内容
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
  • 随后运行 sudo apt-get update 和 sudp apt-get upgrade 更新

  • 输入命令:sudo apt-get install xrdp,按回车,输入y确认安装,等待安装完成
  • 输入命令:sudo apt-get install tightvncserver xrdp,按回车,输入y确认安装,等待安装完成
  • 安装完成后,输入:sudo service xrdp restart,重启xrdp服务
  • 使用Windows自带的远程桌面连接树莓派,输入获得的IP地址,填写账户密码确认连接即可
  • 如上一步骤连接中出现蓝屏时,请执行下方的命令操作
    • 连接好树莓派4B后,输入sudo gpasswd -d X video后回车,其中X为你的账户名称
    • 随后输入sudo gpasswd -d X render后回车,其中X为你的账户名称
    • 输入sudo raspi-config,进入设置页面,依次进入System options -> Boot / Auto Login -> Desktop GUI, requiring user to login,重启后即可解决蓝屏问题

 回车,然后将光标调到Finish,会询问你是否重启,摁下回车确认,等待系统重启即可

安装Python3.7.3

  • 下载python源码包

curl -O https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
  • 解压和打开目录
tar -xf Python-3.7.3.tar.xz
cd Python-3.7.3
  •  生成make编译文件
sudo ./configure --with-ssl
sudo ./configure --enable-optimizations
  •  安装和执行make
sudo make
sudo make altinstall
  • 删除原内置python3和pip3,删除lsb_release
// 替换python
which python3.7
sudo rm -rf /usr/bin/python3
sudo ln -s /usr/local/bin/python3.7 /usr/bin/python3

//替换pip
which pip3.7
sudo rm -rf /usr/bin/pip3
sudo ln -s /usr/local/bin/pip3.7 /usr/bin/pip3

//删除lsb_release
which lsb_release
sudo rm -rf /usr/bin/lsb_release
  • 测试是否安装成功:出现以下内容即为python3.7.3安装成功
qinyaoze@raspberrypi:~/Python-3.7.3 $ python3
Python 3.7.3 (default, Mar 25 2023, 17:19:24)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
qinyaoze@raspberrypi:~/Python-3.7.3 $ 

安装Tensorflow 1.13.1

  • 下载文件
  • 通过Mobaxterm传入文件
  • 安装文件,执行命令
sudo pip3 install tensorflow-1.13.1-cp37-none-linux_armv7l.whl

等待安装完成即可,显示下方内容即为安装成功

或按照下方的内容输入命令框,验证是否安装成功

qinyaoze@raspberrypi:~/Python-3.7.3 $ python3
Python 3.7.3 (default, Mar 26 2023, 21:37:49)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
/usr ...一堆内容,不重要!因为是老版本,会出现很多W很正常
>>> import tensorflow as tf
>>> 
出现上方的空行,即为安装成功

我遇到的问题及解决方案

问题1:protobuf版本错误

解决方案: 

sudo pip3 install protobuf==3.19.0

问题2:No module name '_ctypes'

解决方案:

sudo apt-get install libffi-dev

问题3:OpenSSL

原报错信息提醒:
Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, 
https://github.com/libressl-portable/portable/issues/381

解决方案:

  • 依次执行下方的代码
wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.7.4.tar.gz
tar zxvf libressl-2.7.4.tar.gz
cd libressl-2.7.4
./config --prefix=/usr/local
sudo make install 
sudo nano /etc/ld.so.conf.d/local.conf
添加本行命令:/usr/local/lib
sudo ldconfig -v
回到原Python编译路径:cd /home/你的用户名/Python-3.7.3/Modules/
打开文件:sudo nano Setup
删除有关ssl的代码备注:
SSL=/usr/local
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto
再重新编译Python3.7.3即可

问题4:权限问题

  • 问题情景:当你进行Python3.7.3安装完成测试时,输入exit() 要退出时,出现该错误
profiling:/home/qinyaoze/Python-3.7.3/Parser/parser.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/structmember.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/mystrtoul.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/getcopyright.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/getcompiler.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/ast_unparse.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/ast_opt.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/ast.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/asdl.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/Python-ast.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/namespaceobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/odictobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/iterobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/fileobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/genobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/enumobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/descrobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/complexobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/codeobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/classobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/cellobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/bytearrayobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/bytes_methods.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/accu.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/abstract.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Parser/tokenizer.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Parser/parsetok.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Parser/myreadline.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Parser/node.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Parser/grammar1.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Parser/acceler.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/getbuildinfo.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/xxsubtype.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/symtablemodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/hashtable.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_tracemalloc.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/faulthandler.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/zipimport.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/stringio.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/textio.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/bufferedio.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/bytesio.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/fileio.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/iobase.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_iomodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_localemodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_threadmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/timemodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_stat.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/signalmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/atexitmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/itertoolsmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_abc.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_collectionsmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_operator.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_functoolsmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_weakref.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_codecsmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/_sre.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/pwdmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/errnomodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/posixmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/gcmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/getpath.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/dynload_shlib.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/fileutils.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/formatter_unicode.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/dtoa.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/pystrhex.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/pystrtod.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/pystrcmp.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/getopt.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/traceback.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/thread.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/sysmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/symtable.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/bootstrap_hash.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/pytime.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/pythonrun.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/hamt.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/context.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/pystate.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/pylifecycle.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/pyhash.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/pyarena.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/peephole.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/pathconfig.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/mysnprintf.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/modsupport.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/marshal.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/importdl.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/import.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/getversion.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/getplatform.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/getargs.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/future.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/errors.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/codecs.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/compile.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/ceval.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/bltinmodule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Python/_warnings.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/weakrefobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/unicodectype.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/unicodeobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/typeobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/tupleobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/structseq.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/sliceobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/setobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/rangeobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/capsule.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/obmalloc.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/object.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/moduleobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/methodobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/memoryobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/dictobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/longobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/listobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/funcobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/frameobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/floatobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/exceptions.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/call.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/bytesobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Objects/boolobject.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Modules/main.gcda:Cannot open
profiling:/home/qinyaoze/Python-3.7.3/Programs/python.gcda:Cannot open
qinyaoze@raspberrypi:~/Python-3.7.3 $ Parser/parser.gcda:Cannot open
-bash: Parser/parser.gcda:Cannot: No such file or directory
  • 解决方案:赋予文件夹所有用户权限即可
sudo chmod -R 777 Python3.7.3/

问题4:缺失h5py

  •  解决方案:下载文件 >> 离线本地安装
sudo pip3 install h5py-3.7.0-cp37-cp37m-linux_armv7l.whl

问题5:无法导入libhdfs.so

  • 解决方案: 原安装为1.14.1版本(因为14的pip不兼容部分tf内容),降低到1.13.1即可
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinyaoze

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值