树莓派4B 64位系统 安装python3.7+tensorflow 2.3.1

树莓派4B 64位系统 安装python3.7+tensorflow 2.3.1

参考:https://qengineering.eu/install-tensorflow-2.3.1-on-raspberry-64-os.html

开始之前

首先需要检验系统版本是否为64位,此流程只适合于运行64位系统,若为32位系统,请使用armv7l的tensorflow包(官方有提供)。

(venv) pi@raspbian:~$ uname -a
Linux raspbian 5.4.47-OPENFANS+20200622-v8 #1 SMP PREEMPT Mon Jun 22 21:17:56 CST 2020 aarch64 GNU/Linux

此处可以看到我的系统有【aarch64】字样,即为64位系统。

Step1 安装python及虚拟环境(virtualenv)

sudo apt-get install python3.7
sudo apt-get install pip3
sudo apt-get install python3-pip python3-dev
sudo apt install libatlas-base-dev
sudo pip3 install -U virtualenv

完成后,可以检验一下python等包是否已经正确安装。

pip3 --version
python3 -v

Step2 配置虚拟环境

如果不需要虚拟环境,上面虚拟环境的安装和这一步可以跳过。

virtualenv --system-site-packages -p python3 ./venv
source ./venv/bin/activate
pip install --upgrade pip
# get a fresh start (remember, the 64-bit OS is still under development)
$ sudo apt-get update
$ sudo apt-get upgrade
# install pip and pip3
$ sudo apt-get install python-pip python3-pip
# remove old versions, if not placed in a virtual environment (let pip search for them)
$ sudo pip uninstall tensorflow
$ sudo pip3 uninstall tensorflow
# install the dependencies (if not already onboard)
$ sudo apt-get install gfortran
$ sudo apt-get install libhdf5-dev libc-ares-dev libeigen3-dev
$ sudo apt-get install libatlas-base-dev libopenblas-dev libblas-dev
$ sudo apt-get install liblapack-dev
# upgrade setuptools 47.1.1 -> 50.3.0
$ sudo -H pip3 install --upgrade setuptools
$ sudo -H pip3 install pybind11
$ sudo -H pip3 install Cython==0.29.21
# install h5py with Cython version 0.29.21 (± 6 min @1950 MHz)
$ sudo -H pip3 install h5py==2.10.0
# install TensorFlow (± 63 min @1950 MHz)
$ sudo -H pip3 install tensorflow-2.3.1-cp37-cp37m-linux_aarch64.whl

whl文件可以通过https://github.com/Qengineering/TensorFlow-Raspberry-Pi_64-bit获得。推荐不要使用原文中的gdown方式下载(因为不能访问谷歌网盘),可以使用其他可以科学上网的设备下载好whl文件后通过sftp传到树莓派,然后执行安装即可。

Step3 验证tensorflow安装

键入python3,import tensorflow并显示其版本信息,若出现类似如下输出,则安装成功。

(venv) pi@raspbian:~$ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'2.3.1'
>>>
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页