简体   繁体   English

无法在树莓派 4 上安装 Tensorflow 2.3

[英]Can't install Tensorflow 2.3 on Raspberry Pi 4

I can't currently install TensorFlow 2.3 on a Raspberry Pi 4. Unfortunately, the pip doesn't return any TensorFlow version:我目前无法在 Raspberry Pi 4 上安装 TensorFlow 2.3。不幸的是,pip 没有返回任何 TensorFlow 版本:

pip install tensorflow==
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
ERROR: Could not find a version that satisfies the requirement tensorflow==
ERROR: No matching distribution found for tensorflow==

I read somewhere that TensorFlow only supports the 64-bit version of Python and only the versions between 3.5 to 3.8 so I made sure that I have these versions installed as well.我在某处读到 TensorFlow 仅支持 64 位版本的 Python 并且仅支持 3.5 到 3.8 之间的版本,所以我确保我也安装了这些版本。

The current Linux distro that I have is the following aarch64 .我拥有的当前 Linux 发行版是以下aarch64

pip and python have the following versions: pippython有以下版本:

pip -V python
pip 20.3.1 from /home/pi/envs/awe/lib/python3.7/site-packages/pip (python 3.7)

python -V
Python 3.7.3

And I also have a 64-bit version of Python:而且我还有一个 64 位版本的 Python:

platform.architecture()
('64bit', 'ELF')

Why can't pip find a compatible TensorFlow of version 2.3?为什么pip找不到兼容2.3版本的TensorFlow?

For the Raspberry Pi 4 ARM64 platform TensorFlow is not available as pre-built version for pip and must be compiled manually.对于 Raspberry Pi 4 ARM64 平台,TensorFlow 不可用作 pip 的预构建版本,必须手动编译。 Follow these instructions and cross compile it on a different more powerful environment, not on the Pi 4. The instructions are no up to date anymore, I have completed them here.按照这些说明在不同的更强大的环境中交叉编译它,而不是在 Pi 4 上。这些说明不再是最新的,我已经在这里完成了。 These are the steps to cross compile TensorFlow 2.3.1 on an Ubuntu Linux:这些是在 Ubuntu Linux 上交叉编译 TensorFlow 2.3.1 的步骤:

git clone git@github.com:tensorflow/tensorflow.git
cd tensorflow

The old version 2.3.1 does not know Python 3.8.老版本2.3.1不知道Python 3.8。 When using Python 3.7 then this might not be necessary.当使用 Python 3.7 时,这可能不是必需的。

wget https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/ci_build/Dockerfile.pi-python38 -o tensorflow/tools/ci_build/Dockerfile.pi-python38

CMake is now also required, I'm using here the master branch, which is of version 2.5.0 (in case this does not work anymore in the future with the master version):现在还需要 CMake,我在这里使用的是 2.5.0 版本的 master 分支(以防将来在 master 版本中不再适用):

wget -O tensorflow/tools/ci_build/install/install_cmake.sh https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/tools/ci_build/install/install_cmake.sh
chmod +x tensorflow/tools/ci_build/install/install_cmake.sh

To support Python 3.8 add support for it, again taken from the master branch (version 2.5.0):为了支持 Python 3.8 添加对它的支持,再次取自 master 分支(版本 2.5.0):

wget -O tensorflow/tools/ci_build/install/install_pi_python3x_toolchain.sh https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/tools/ci_build/install/install_pi_python3x_toolchain.sh
chmod +x tensorflow/tools/ci_build/install/install_pi_python3x_toolchain.sh

You also need these file for the build:您还需要这些文件进行构建:

wget -O tensorflow/tools/ci_build/pi/build_raspberry_pi.sh https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/tools/ci_build/pi/build_raspberry_pi.sh
chmod +x tensorflow/tools/ci_build/pi/build_raspberry_pi.sh

There is an issue with newer numpy version.较新的numpy版本存在问题。 Use this cherry-pick from git:使用 git 中的这个精选:

git cherry-pick 75ea0b31477d6ba9e990e296bbbd8ca4e7eebadf

Now finally this can be compiled.现在终于可以编译了。 This takes several hours most likely.这很可能需要几个小时。

tensorflow/tools/ci_build/ci_build.sh PI-PYTHON38 tensorflow/tools/ci_build/pi/build_raspberry_pi.sh AARCH64

If something fails and some files have to be patched or added keep in mind to clean the Docker container to prevent using the Docker cache when restarting the build process.如果出现故障并且必须修补或添加某些文件,请记住清理 Docker 容器,以防止在重新启动构建过程时使用 Docker 缓存。 docker images , docker rmi <imageid> and docker rm <container> are your friends. docker images , docker rmi <imageid>docker rm <container>是你的朋友。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM