无法在 raspberry pi 3b+ 上安装 tensorflow

Cannot install tensorflow on raspberry pi 3b+

当我尝试在 raspberry pi 3b+ 上使用 pip 安装 tensorflow 时,我 运行 遇到了错误。

错误信息如下:

Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-p4UFOu/h5py/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-ofsmSC/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-p4UFOu/h5py/

这是我尝试的命令,它给出了我提到的错误:

sudo pip install tensorflow

我是 运行 Raspbian OS 的最新版本并且已经更新和升级了我的 raspberry pi。我也在使用 python 2.7,这在我的 ubuntu 18.10 笔记本电脑上与 python 2.7 一起成功运行。

有什么办法可以成功做到这一点吗?

根据 /tmp/pip-install-p4UFOu/h5py/setup.py 的猜测,您在安装 tensorflow 所需的 h5py 软件包时遇到了问题。由于您是从源代码构建 h5py(预构建的 ARM 轮仅适用于 Python 3.4/3.5 atm),请参阅 h5py installation docs:

To install h5py from source, you need three things installed:

  • A supported Python version with development headers
  • HDF5 1.8.4 or newer with development headers
  • A C compiler

在 Raspbian 和 Python 2 上,这转换为:

  • apt install python-dev
  • apt install libhdf5-dev
  • apt install gcc(或者,如果您希望一次安装整个开发工具,apt install build-essential

现在 pip install h5py 应该拥有正确构建和安装包的一切。