Q:

Cannot install tensorflow on raspberry pi 3b+

I am running into an error when I try to install tensorflow using pip on my raspberry pi 3b+.
Here is the error message:
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/

Here is the command I tried that gave the error I mentioned:
sudo pip install tensorflow

I am running the latest version of Raspbian OS and have updated and upgraded my raspberry pi. I am also using python 2.7 and this works successfully with python 2.7 on my ubuntu 18.10 laptop.
Any ideas how I can successfully do this?

A:

Guessing by /tmp/pip-install-p4UFOu/h5py/setup.py, you have the issues with installing the h5py package which is required by tensorflow. Since you are building h5py from source (the prebuilt ARM wheels exist for Python 3.4/3.5 only atm), refer to the 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

On Raspbian and Python 2, this translates to:

apt install python-dev
apt install libhdf5-dev
apt install gcc (or, if you want the whole development tools to be installed at once, apt install build-essential)

Now pip install h5py should have everything to build and install the package properly.

