0

I will try to be as much detailed as possible. I am currently in need to use TensorFlow in Pyhton.

  1. My PC runs in Ubuntu, and my ubuntu version is this:

    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 16.04.6 LTS
    Release:    16.04
    Codename:   xenial
    
  2. If I type python in terminal, I get:

    $ python
    Python 2.7.12 (default, Mar  1 2021, 11:38:31) 
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    

So my default python version is Python 2.7.12

  1. I have installed pyhton3.5 following this instrucions and python3.9 following this page. While installing, both sets of instructions run (kind of) OK.

  2. If I type $ ll /usr/bin/python* I get:

    $ ll /usr/bin/python*
    lrwxrwxrwx 1 root root       9 nov 23  2017 /usr/bin/python -> python2.7*
    lrwxrwxrwx 1 root root       9 nov 23  2017 /usr/bin/python2 -> python2.7*
    -rwxr-xr-x 1 root root 3492624 mar  1 17:47 /usr/bin/python2.7*
    lrwxrwxrwx 1 root root      33 mar  1 17:47 /usr/bin/python2.7-config -> x86_64-linux-        gnu-python2.7-config*
    lrwxrwxrwx 1 root root      16 nov 23  2017 /usr/bin/python2-config -> python2.7-config*
    -rwxr-xr-x 1 root root     306 oct 23  2015 /usr/bin/python2-futurize*
    -rwxr-xr-x 1 root root     310 oct 23  2015 /usr/bin/python2-pasteurize*
    -rwxr-xr-x 1 root root     151 nov 23  2015 /usr/bin/python2-pbr*
    lrwxrwxrwx 1 root root       9 sep 13  2017 /usr/bin/python3 -> python3.5*
    -rwxr-xr-x 2 root root 4456208 ene 26 15:48 /usr/bin/python3.5*
    -rwxr-xr-x 2 root root 4456208 ene 26 15:48 /usr/bin/python3.5m*
    -rwxr-xr-x 2 root root 4604496 may  7  2019 /usr/bin/python3.6*
    -rwxr-xr-x 2 root root 4604496 may  7  2019 /usr/bin/python3.6m*
    -rwxr-xr-x 1 root root     306 oct 23  2015 /usr/bin/python3-futurize*
    lrwxrwxrwx 1 root root      10 sep 13  2017 /usr/bin/python3m -> python3.5m*
    -rwxr-xr-x 1 root root     310 oct 23  2015 /usr/bin/python3-pasteurize*
    -rwxr-xr-x 1 root root     152 nov 23  2015 /usr/bin/python3-pbr*
    lrwxrwxrwx 1 root root      16 nov 23  2017 /usr/bin/python-config -> python2.7-config*
    lrwxrwxrwx 1 root root      58 mar 25  2016 /usr/bin/pythontex ->         ../share/texlive/texmf-dist/scripts/pythontex/pythontex.py*
    -rwxr-xr-x 1 root root     306 mar 25  2016 /usr/bin/pythontex3*
    

So it looks like I have many Pyhton versions installed. I can run them by typing:

    $ python3.5
    Python 3.5.2 (default, Jan 26 2021, 13:30:48) 
    [GCC 5.4.0 20160609] on Linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    [8]+  Detenido                python3.5
    
    $ python3.9
    Python 3.9.0 (default, Mar 31 2021, 09:57:03) 
    [GCC 5.4.0 20160609] on Linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

So it looks that they are there (just not as default!) and they work.

  1. Now, when installing tensorflow, as per these instructions, I get:

    $ sudo pip install tensorflow-cpu
    DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. 
    Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will
    drop support for Python 3.5 in January 2021. pip 21.0 will remove support for
    this functionality.
    WARNING: The directory '/home/myname/.cache/pip' or its parent directory is
    not owned or is not writable by the current user. The cache has been disabled. Check
    the permissions and owner of that directory. If executing pip with sudo, you may want
    sudo's -H flag.
    ....
    ....
    
  2. My pip version is:

    $ pip --version
    pip 20.3.4 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
    

7. And finally, my problem is that when trying to run tensorflow in pyhton I get this:

    $ python
    Python 2.7.12 (default, Mar  1 2021, 11:38:31) 
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tensorflow as tf
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named tensorflow
    >>>

No matter in which python I run it. I get the same.

  • What am I doing wrong?
  • Do I just have to change something in the PATH of my system?
  • What do I change?
  • How do I do it? I am really not a tech person and I get lost easily when things like "path" and stuff get in the middle. If anyone can help me it would be awesome, and I will be grateful.

Extra relevant data:

$ pip show tensorflow
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
Name: tensorflow
Version: 2.3.1
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0
Location: /home/myname/.local/lib/python3.5/site-packages
Requires: wrapt, grpcio, keras-preprocessing, numpy, tensorflow-estimator, opt-einsum, six, wheel, absl-py, h5py, protobuf, tensorboard, gast, astunparse, google-pasta, termcolor
Required-by: 

So actually, it seems that tensorflow is, at least, installed.

And also tried this, from here, with no success:

$ pip install tensorflow --ignore-installed --user
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
....
....
....
....
  WARNING: The script chardetect is installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts easy_install and easy_install-3.5 are installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts pyrsa-decrypt, pyrsa-encrypt, pyrsa-keygen, pyrsa-priv2pub, pyrsa-sign and pyrsa-verify are installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script wheel is installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts f2py, f2py3 and f2py3.5 are installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script markdown_py is installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script google-oauthlib-tool is installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script tensorboard is installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts estimator_ckpt_converter, saved_model_cli, tensorboard, tf_upgrade_v2, tflite_convert, toco and toco_from_protos are installed in '/home/myname/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
....
....
GEBRU
  • 495
  • 2
  • 11
  • You should be using python3.6+ for best stability. I saw you have python3.9 installed, maybe try to use pip3.9 to install tensorflow and use it for running script as well. – TYZ Mar 31 '21 at 20:29
  • If you are not sure which python you are installing for you can always do `python3.9 -m pip install tensorflow-cpu`. Note that the destination of the installation is determined in `~/.config/pip/pip.conf`. – Dov Grobgeld Mar 31 '21 at 20:33
  • I tryied both python3.9....and pip3.9 and get: $ python3.9 -m pip install tensorflow-cpu Defaulting to user installation because normal site-packages is not writeable ERROR: Could not find a version that satisfies the requirement tensorflow-cpu (from versions: none) ERROR: No matching distribution found for tensorflow-cpu WARNING: You are using pip version 20.2.3; however, version 21.0.1 is available. You should consider upgrading via the '/usr/local/bin/python3.9 -m pip install --upgrade pip' command. What is this saying? – GEBRU Mar 31 '21 at 20:51

1 Answers1

0

I think, you can change default python3 for your system via update-alternatives

more information here

Arseniy
  • 680
  • 5
  • 10
  • I did this a few minutes ago: $sudo ln -s /usr/bin/python3.5 /usr/bin/python which apparently set my default to python3.5. Is there any significant difference from what you get by doing update-alternatives ?. Now I am wondering if I just did something wrong. – GEBRU Mar 31 '21 at 20:59