MikeDS
Posts: 8
Joined: Mon Aug 06, 2018 7:05 pm

Difficulty installing tensorflow

Mon Aug 06, 2018 7:09 pm

Hi. I’m trying to install tensorflow, but I’m having a problem with pip3 and then with tensorflow itself. See below.

Code: Select all

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Aug  5 20:25:39 2018 from 192.168.1.128
[email protected]:~$ pip3 install tensorflow
-bash: pip3: command not found
[email protected]:~$ python3 --version
Python 3.4.2
[email protected]:~$ sudo apt-get install python3-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-pip is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
[email protected]:~$ python3-pip install tensorflow
-bash: python3-pip: command not found
[email protected]:~$ pip install tensorflow
Collecting tensorflow
  Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
[email protected]:~$
Appreciate any help the can get me unstuck. Thank you

bertlea
Posts: 180
Joined: Wed Dec 07, 2016 6:33 am
Location: Hong Kong

Re: Difficulty installing tensorflow

Tue Aug 07, 2018 5:15 am

What is your Raspbian version? I am using Stretch April 2018 release.

I just tried on my Pi Zero W using pip3. I followed the general steps from the site https://www.tensorflow.org/install/install_linux, but I am using python3/pip3 and I use the built-in venv to create a vitural environment for the installation.
It took a very long time (over 3 hours) to complete, and I got some errors about installing wheel for numpy and clean up the numpy installation....etc. But I think it was successfully done (see below testing) even it got some python version warnings. It took a long time and it need to use the swap memory (file) for compiling/linking numpy and grpcio. I guess you can do better job by install numpy and grpcio first or install bdist_wheel first.

post-installation testing:

Code: Select all

(venv) [email protected]:~/temp/pytf $ python
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
/usr/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)
/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: builtins.type size changed, may indicate binary incompatibility. Expected 432, got 412
  return f(*args, **kwds)
/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 56, got 52
  return f(*args, **kwds)
>>> a = tf.constant([1,2,3], shape=[3,1])
>>> b = tf.constant([4,5,6], shape=[1,3])
>>> c = tf.matmul(a, b)
>>> sess = tf.Session()
>>> print(sess.run(c))
[[ 4  5  6]
 [ 8 10 12]
 [12 15 18]]
>>>

bertlea
Posts: 180
Joined: Wed Dec 07, 2016 6:33 am
Location: Hong Kong

Re: Difficulty installing tensorflow

Tue Aug 07, 2018 5:52 am

Adding the installation log for your reference:

Code: Select all

[email protected]:~/temp/pytf $ source venv/bin/activate
(venv) [email protected]:~/temp/pytf $
(venv) [email protected]:~/temp/pytf $ pip3 install -U tensorflow
Collecting tensorflow
  Downloading https://www.piwheels.org/simple/tensorflow/tensorflow-1.9.0-cp35-none-linux_armv6l.whl (62.8MB)
    100% |████████████████████████████████| 62.8MB 1.1kB/s
Collecting wheel>=0.26 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl (41kB)
    100% |████████████████████████████████| 51kB 573kB/s
Collecting absl-py>=0.1.6 (from tensorflow)
  Downloading https://www.piwheels.org/simple/absl-py/absl_py-0.3.0-py3-none-any.whl (100kB)
    100% |████████████████████████████████| 102kB 36kB/s
Collecting setuptools<=39.1.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/8c/10/79282747f9169f21c053c562a0baa21815a8c7879be97abd930dbcf862e8/setuptools-39.1.0-py2.py3-none-any.whl (566kB)
    100% |████████████████████████████████| 573kB 137kB/s
Collecting tensorboard<1.10.0,>=1.9.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/9e/1f/3da43860db614e294a034e42d4be5c8f7f0d2c75dc1c428c541116d8cdab/tensorboard-1.9.0-py3-none-any.whl (3.3MB)
    100% |████████████████████████████████| 3.3MB 27kB/s
Collecting grpcio>=1.8.6 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/8a/5f/3f8ae67af2e56c36d62b1d047bddd421a7502fbedd9daf2e6c2049a71424/grpcio-1.14.0.tar.gz (14.4MB)
    100% |████████████████████████████████| 14.4MB 6.2kB/s
Collecting protobuf>=3.4.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/85/f8/d09e4bf21c4de65405ce053e90542e728c5b7cf296b9df36b0bf0488f534/protobuf-3.6.0-py2.py3-none-any.whl (390kB)
    100% |████████████████████████████████| 399kB 198kB/s
Collecting termcolor>=1.1.0 (from tensorflow)
  Downloading https://www.piwheels.org/simple/termcolor/termcolor-1.1.0-py3-none-any.whl
Collecting astor>=0.6.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/35/6b/11530768cac581a12952a2aad00e1526b89d242d0b9f59534ef6e6a1752f/astor-0.7.1-py2.py3-none-any.whl
Collecting six>=1.10.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting numpy>=1.13.3 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/3a/20/c81632328b1a4e1db65f45c0a1350a9c5341fd4bbb8ea66cdd98da56fe2e/numpy-1.15.0.zip (4.5MB)
    100% |████████████████████████████████| 4.5MB 14kB/s
Collecting gast>=0.2.0 (from tensorflow)
  Downloading https://www.piwheels.org/simple/gast/gast-0.2.0-py3-none-any.whl
Collecting werkzeug>=0.11.10 (from tensorboard<1.10.0,>=1.9.0->tensorflow)
  Downloading https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
    100% |████████████████████████████████| 327kB 241kB/s
Collecting markdown>=2.6.8 (from tensorboard<1.10.0,>=1.9.0->tensorflow)
  Downloading https://files.pythonhosted.org/packages/6d/7d/488b90f470b96531a3f5788cf12a93332f543dbab13c423a5e7ce96a0493/Markdown-2.6.11-py2.py3-none-any.whl (78kB)
    100% |████████████████████████████████| 81kB 543kB/s
Building wheels for collected packages: grpcio, numpy
  Running setup.py bdist_wheel for grpcio ... error
  Complete output from command /home/pi/temp/pytf/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-x_9_4m7y/grpcio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpa47275hhpip-wheel- --python-tag cp35:
  Found cython-generated files...
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help

  error: invalid command 'bdist_wheel'

  ----------------------------------------
  Failed building wheel for grpcio
  Running setup.py clean for grpcio
  Running setup.py bdist_wheel for numpy ... error
  Complete output from command /home/pi/temp/pytf/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-x_9_4m7y/numpy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpdu3t81j4pip-wheel- --python-tag cp35:
  Running from numpy source directory.
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help

  error: invalid command 'bdist_wheel'

  ----------------------------------------
  Failed building wheel for numpy
  Running setup.py clean for numpy
  Complete output from command /home/pi/temp/pytf/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-x_9_4m7y/numpy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" clean --all:
  Running from numpy source directory.

  `setup.py clean` is not supported, use one of the following instead:

    - `git clean -xdf` (cleans all files)
    - `git clean -Xdf` (cleans all versioned files, doesn't touch
                        files that aren't checked into the git repo)

  Add `--force` to your command to use it anyway if you must (unsupported).


  ----------------------------------------
  Failed cleaning build dir for numpy
Failed to build grpcio numpy
Installing collected packages: wheel, six, absl-py, setuptools, werkzeug, numpy, markdown, protobuf, tensorboard, grpcio, termcolor, astor, gast, tensorflow
  Found existing installation: setuptools 33.1.1
    Uninstalling setuptools-33.1.1:
      Successfully uninstalled setuptools-33.1.1
  Running setup.py install for numpy ... done
  Running setup.py install for grpcio ... done
Successfully installed absl-py-0.3.0 astor-0.7.1 gast-0.2.0 grpcio-1.14.0 markdown-2.6.11 numpy-1.15.0 protobuf-3.6.0 setuptools-39.1.0 six-1.11.0 tensorboard-1.9.0 tensorflow-1.9.0 termcolor-1.1.0 werkzeug-0.14.1 wheel-0.31.1

DirkS
Posts: 9221
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Difficulty installing tensorflow

Tue Aug 07, 2018 5:59 am

bertlea wrote:
Tue Aug 07, 2018 5:15 am
I just tried on my Pi Zero W using pip3. I followed the general steps from the site https://www.tensorflow.org/install/install_linux, but I am using python3/pip3 and I use the built-in venv to create a vitural environment for the installation.
You should use https://www.tensorflow.org/install/install_raspbian instead
You can of course still use a virtual environment

bertlea
Posts: 180
Joined: Wed Dec 07, 2016 6:33 am
Location: Hong Kong

Re: Difficulty installing tensorflow

Tue Aug 07, 2018 6:13 am

@DirkS Yes! I should follow your link instead.

MikeDS
Posts: 8
Joined: Mon Aug 06, 2018 7:05 pm

Re: Difficulty installing tensorflow

Wed Aug 08, 2018 10:33 am

The version of Raspbian is Jessie.

DirkS
Posts: 9221
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Difficulty installing tensorflow

Wed Aug 08, 2018 10:51 am

MikeDS wrote:
Wed Aug 08, 2018 10:33 am
The version of Raspbian is Jessie.
Not sure why the last command in your first post did not work...

First I would upgrade pip3:

Code: Select all

sudo pip3 install -U pip
Then follow the instructions I linked to above, which boils down to

Code: Select all

sudo apt update
sudo apt install libatlas-base-dev
sudo pip3 install tensorflow
Post any error messages here.

DirkS
Posts: 9221
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Difficulty installing tensorflow

Wed Aug 08, 2018 5:07 pm

Just found out that the tenorflow for the Pi is only available from Ben Nuttall's piwheels.
You need to create /etc/pip.conf

Code: Select all

sudo nano /etc/pip.conf
and add

Code: Select all

[global]
extra-index-url=https://www.piwheels.org/simple
and then run the pip3 install command.

I don't know if there is a version for Python 3.4 (installed on Raspbian Jessie)

MikeDS
Posts: 8
Joined: Mon Aug 06, 2018 7:05 pm

Re: Difficulty installing tensorflow

Thu Aug 09, 2018 11:11 am

DirkS wrote:
Wed Aug 08, 2018 10:51 am

First I would upgrade pip3:

Code: Select all

sudo pip3 install -U pip
pip3 command is not recognized. See my first post
:(

DirkS
Posts: 9221
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Difficulty installing tensorflow

Thu Aug 09, 2018 2:42 pm

MikeDS wrote:
Thu Aug 09, 2018 11:11 am
DirkS wrote:
Wed Aug 08, 2018 10:51 am

First I would upgrade pip3:

Code: Select all

sudo pip3 install -U pip
pip3 command is not recognized. See my first post
:(
Can't see you using pip3 in that post. You tried python3-pip which is the name of the package, not the program.
The log in your first post shows that the package pip3-python is installed, so the 'pip3' should be a valid command.

Have you actually tried the update command above? If it fails then please post the full error message.

MikeDS
Posts: 8
Joined: Mon Aug 06, 2018 7:05 pm

Re: Difficulty installing tensorflow

Thu Aug 16, 2018 11:07 am

DirkS wrote:
Thu Aug 09, 2018 2:42 pm

Can't see you using pip3 in that post. You tried python3-pip which is the name of the package, not the program.
The log in your first post shows that the package pip3-python is installed, so the 'pip3' should be a valid command.

Have you actually tried the update command above? If it fails then please post the full error message.

The reason why I tried the package name is because the program didn't work.

Code: Select all

sudo: pip3: command not found

DirkS
Posts: 9221
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Difficulty installing tensorflow

Thu Aug 16, 2018 1:09 pm

Try the following to install pip3

Code: Select all

wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py

MikeDS
Posts: 8
Joined: Mon Aug 06, 2018 7:05 pm

Re: Difficulty installing tensorflow

Thu Aug 16, 2018 1:21 pm

DirkS wrote:
Thu Aug 16, 2018 1:09 pm
Try the following to install pip3

Code: Select all

wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
Collecting pip
Using cached https://files.pythonhosted.org/packages ... d3f3144150
a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.w
l
Installing collected packages: pip
Found existing installation: pip 1.5.6
Uninstalling pip-1.5.6:
Successfully uninstalled pip-1.5.6
Successfully installed pip-18.0

When trying to install tf:

pts$ pip3 install tensorflow
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from
versions: )
No matching distribution found for tensorflow

DirkS
Posts: 9221
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Difficulty installing tensorflow

Thu Aug 16, 2018 5:23 pm

MikeDS wrote:
Thu Aug 16, 2018 1:21 pm
No matching distribution found for tensorflow
Did you create /etc/pip.conf as I mentioned a couple of posts ago?

bertlea
Posts: 180
Joined: Wed Dec 07, 2016 6:33 am
Location: Hong Kong

Re: Difficulty installing tensorflow

Fri Aug 17, 2018 3:06 am

@DirkS, a hypothetical question: Will it work if I just zip my venv folder that contained the tensorflow package I compiled/installed and send to MikeDS. Then MikeDS just unzip that to his Raspberry Pi and able to use it under venv? Just a hypothetical question, not suggesting do it that way. I would like to understand Python venv better as I am also learning Python.

DirkS
Posts: 9221
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Difficulty installing tensorflow

Fri Aug 17, 2018 6:41 am

bertlea wrote:
Fri Aug 17, 2018 3:06 am
@DirkS, a hypothetical question: Will it work if I just zip my venv folder that contained the tensorflow package I compiled/installed and send to MikeDS. Then MikeDS just unzip that to his Raspberry Pi and able to use it under venv? Just a hypothetical question, not suggesting do it that way. I would like to understand Python venv better as I am also learning Python.
Sorry, don't know. In general these things tend to cause more problems than solutions.

bertlea
Posts: 180
Joined: Wed Dec 07, 2016 6:33 am
Location: Hong Kong

Re: Difficulty installing tensorflow

Fri Aug 17, 2018 7:26 am

I see. Thank you DirkS anyway.

MikeDS
Posts: 8
Joined: Mon Aug 06, 2018 7:05 pm

Re: Difficulty installing tensorflow

Mon Aug 20, 2018 2:06 pm

DirkS wrote:
Thu Aug 16, 2018 5:23 pm
MikeDS wrote:
Thu Aug 16, 2018 1:21 pm
No matching distribution found for tensorflow
Did you create /etc/pip.conf as I mentioned a couple of posts ago?

I did now. Sorry, I shouldn't be doing all this on my phone. It seemed to be working, until it got stuck again:

Installing collected packages: termcolor, six, protobuf, gast, numpy, whee
, markdown, werkzeug, tensorboard, absl-py, astor, grpcio, tensorflow
Found existing installation: six 1.8.0
Uninstalling six-1.8.0:
Successfully uninstalled six-1.8.0
Found existing installation: numpy 1.8.2
Cannot uninstall 'numpy'. It is a distutils installed project and thus we
annot accurately determine which files belong to it which would lead to only a partial uninstall.

DirkS
Posts: 9221
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Difficulty installing tensorflow

Mon Aug 20, 2018 2:20 pm

MikeDS wrote:
Mon Aug 20, 2018 2:06 pm
Found existing installation: numpy 1.8.2
Cannot uninstall 'numpy'. It is a distutils installed project and thus we
annot accurately determine which files belong to it which would lead to only a partial uninstall.
That's an older version fro the Raspbian repo

I would just install it using apt-get and then use pip3 to install a current version:

Code: Select all

sudo apt-get remove python3-numpy
sudo pip3 install numpy

MikeDS
Posts: 8
Joined: Mon Aug 06, 2018 7:05 pm

Re: Difficulty installing tensorflow

Mon Aug 20, 2018 3:21 pm

Can I call this a success?

Code: Select all

@pi3:~/shared/scripts/tensorflow$ nano teste.py
[email protected]:~/shared/scripts/tensorflow$ python teste.py
Traceback (most recent call last):
  File "teste.py", line 1, in <module>
    import tensorflow as tf
ImportError: No module named tensorflow
[email protected]:~/shared/scripts/tensorflow$ python3 teste.py
/usr/lib/python3.4/importlib/_bootstrap.py:321: RuntimeWarning: numpy.dtyp
 size changed, may indicate binary incompatibility. Expected 56, got 52
  return f(*args, **kwds)
b'hello!'

DirkS
Posts: 9221
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Difficulty installing tensorflow

Mon Aug 20, 2018 3:55 pm

MikeDS wrote:
Mon Aug 20, 2018 3:21 pm
Can I call this a success?
Yes, I think so. :D
I get a similar warning on my Pi with Raspbian Stretch.

MikeDS
Posts: 8
Joined: Mon Aug 06, 2018 7:05 pm

Re: Difficulty installing tensorflow

Mon Aug 20, 2018 4:13 pm

DirkS wrote:
Mon Aug 20, 2018 3:55 pm
MikeDS wrote:
Mon Aug 20, 2018 3:21 pm
Can I call this a success?
Yes, I think so. :D
I get a similar warning on my Pi with Raspbian Stretch.
Awesome! Thanks a bunch!

metalalive
Posts: 3
Joined: Wed Dec 06, 2017 4:28 pm
Location: Taipei

Re: Difficulty installing tensorflow

Sun Sep 16, 2018 2:20 pm

DirkS wrote:
Wed Aug 08, 2018 5:07 pm
Just found out that the tenorflow for the Pi is only available from Ben Nuttall's piwheels.
You need to create /etc/pip.conf

Code: Select all

sudo nano /etc/pip.conf
and add

Code: Select all

[global]
extra-index-url=https://www.piwheels.org/simple
and then run the pip3 install command.

I don't know if there is a version for Python 3.4 (installed on Raspbian Jessie)
my command for installing tensorflow is "pip3 install --user tensorflow"
without the option --user , you might get permission denied in the middle of installation,
anyway DirkS's suggestion + official installation steps work pretty well on my Raspbain stretch,
thanks :D.

DirkS
Posts: 9221
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Difficulty installing tensorflow

Sun Sep 16, 2018 2:43 pm

metalalive wrote:
Sun Sep 16, 2018 2:20 pm
my command for installing tensorflow is "pip3 install --user tensorflow"
without the option --user , you might get permission denied in the middle of installation,
Well, that's exactly why you would normally use

Code: Select all

sudo pip3 install tensorflow
That way it is installed globally (for all users).
I would install it in a virtual environment anyway.

Return to “Python”