0

With a new SD card and Raspbian version Stretch 2018-11-13:

sudo apt install -y python3-pip python3-dev python-virtualenv
virtualenv -p python3.5 --system-site-packages myenv
source myenv/bin/activate
pip3 install --upgrade tensorflow
$ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
/home/pi/myenv/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: compiletime version 3.4 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.5
  return f(*args, **kwds)
/home/pi/myenv/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: builtins.type size changed, may indicate binary incompatibility. Expected 432, got 412
  return f(*args, **kwds)
>>> 
karel
  • 5,489
  • 46
  • 45
  • 50

1 Answers1

1

Check if your Python environment is already configured (requires Python 3.4, 3.5, or 3.6):

The version of the tensorflow package that is installed by sudo python3 -m pip install --user --upgrade tensorflow has been upgraded since this question was originally posted. When this answer was last edited it required Python 3.7, 3.8, or 3.9. Check the current version of tensorflow at https://pypi.org/project/tensorflow/ before you install it.

python3 --version
pip3 --version
virtualenv --version

Install these packages if necessary:

sudo apt update  
sudo apt install python3 python3-pip

TensorFlow requirements for the Raspbian operating system:

sudo apt update
sudo apt install python3-dev python3-pip  
sudo apt install libatlas-base-dev        # required for numpy  
sudo python3 -m pip install --upgrade pip  
sudo python3 -m pip install --upgrade virtualenv    # system-wide install  

Create a new virtual environment by choosing a Python interpreter and making a myenv directory to hold it:

virtualenv --system-site-packages -p python3 myenv

As you mentioned in your question, the python3 package version in Debian Stretch is 3.5.

Install TensorFlow (system install):

sudo python3 -m pip install --user --upgrade tensorflow 

Verify the install:

python3 -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"

IMG: Success: TensorFlow is now installed. Read the tutorials to get started.

karel
  • 5,489
  • 46
  • 45
  • 50