【问题标题】:Can't install Tensorflow 2.3 on Raspberry Pi 4无法在 Raspberry Pi 4 上安装 Tensorflow 2.3
【发布时间】:2021-03-20 19:34:19
【问题描述】:

我目前无法在 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==

我在某处读到 TensorFlow 只支持 64 位版本的 Python,并且只支持 3.5 到 3.8 之间的版本,所以我确保我也安装了这些版本。

我目前拥有的 Linux 发行版如下aarch64

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

我还有一个 64 位版本的 Python:

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

为什么 pip 找不到兼容的 TensorFlow 2.3 版本?

【问题讨论】:

  • 因为aarch64 平台标签没有预构建的轮子。您必须从源代码构建 Tensorflow 2。
  • 我在这里和那里看到过用于aarch64 的非官方TF2 车轮,但没有尝试过;例如,查看here。当然,使用风险自负。
  • 感谢您的回复@hoefling!是否有任何可在 Raspberry 4 上运行的平台的预构建轮子?我需要 TensorFlow 2.3 并且在哪个平台上运行这没什么大不了的。
  • @UrmLmn 没有专门为特定 Raspberry Pi 型号预构建的轮子;相反,您必须检查您的体系结构(显然是 ARM)和位数(这取决于您的操作系统;尽管 RPi4 具有 64 位 CPU,但 Raspbian 本身仍然是 32 位等)。对于 ARM 32 位,使用带有标签 linux-armv7l 的轮子;对于 64 位 ARM,这将是 linux-aarch64。两个轮子都可以在我上面发布的回购中找到。

标签: python tensorflow pip raspberry-pi tensorflow2.0


【解决方案1】:

对于 Raspberry Pi 4 ARM64 平台,TensorFlow 不能作为 pip 的预构建版本提供,必须手动编译。 按照这些instructions 并在另一个更强大的环境中交叉编译它,而不是在 Pi 4 上。说明不再是最新的,我在这里完成了。以下是在 Ubuntu Linux 上交叉编译 TensorFlow 2.3.1 的步骤:

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

旧版本 2.3.1 不知道 Python 3.8。在使用 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,我这里使用的是 master 分支,它对应于 2.5.0 版本(以防将来在 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

为了支持 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

您还需要这些文件进行构建:

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

较新的numpy 版本存在问题。使用 git 中的这个樱桃选择:

git cherry-pick 75ea0b31477d6ba9e990e296bbbd8ca4e7eebadf

现在终于可以编译了。这很可能需要几个小时。

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

如果出现故障并且必须修补或添加某些文件,请记住清理 Docker 容器,以防止在重新启动构建过程时使用 Docker 缓存。 docker imagesdocker rmi <imageid>docker rm <container> 是你的朋友。

【讨论】:

    猜你喜欢
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 2021-12-14
    • 1970-01-01
    • 2021-06-03
    相关资源
    最近更新 更多