ImportError: No module named tensorflow

426,825

Solution 1

Try installing tensorflow again with the whatever version you want and with option --ignore-installed like:

pip install tensorflow==1.2.0 --ignore-installed

I solved same issue using this command.

Solution 2

I had a more basic problem when I received this error.

The "Validate your installation" instructions say to type: python

However, I have both 2.7 and 3.6 installed. Because I used pip3 to install tensorflow, I needed to type: python3

Using the correct version, I could import the "tensorflow" module.

Solution 3

Check if Tensorflow was installed successfully using:

 pip3 show tensorflow

If you get something like

Name: tensorflow
Version: 1.2.1
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: /usr/local/lib/python3.5/dist-packages
Requires: bleach, markdown, html5lib, backports.weakref, werkzeug, numpy, protobuf, wheel, six

You may try adding the path of your tensorflow location by:

export PYTHONPATH=/your/tensorflow/path:$PYTHONPATH.

Solution 4

For Anaconda3, simply install in Anaconda Navigator: enter image description here

Solution 5

Try installing tensorflow in the user site - This installation only works for you.

pip install tensorflow --user

Share:
426,825
Abhishek Gangwar
Author by

Abhishek Gangwar

Updated on September 07, 2021

Comments

  • Abhishek Gangwar
    Abhishek Gangwar over 2 years

    Please help me with this error

    I have installed the tensorflow module on my server and below is it's information

    15IT60R19@cpusrv-gpu-109:~$ pip show tensorflow
    Name: tensorflow
    Version: 1.0.0
    Summary: TensorFlow helps the tensors flow
    Home-page: http://tensorflow.org/
    Author: Google Inc.
    Author-email: [email protected]
    License: Apache 2.0
    Location: /home/other/15IT60R19/anaconda2/lib/python2.7/site-packages
    Requires: mock, numpy, protobuf, wheel, six
    

    But when I try to import tensorflow I get following error

    >>> import tensorflow as tf
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named tensorflow
    

    My python version is as following

    Python 2.7.12 |Anaconda 2.5.0 (64-bit)| (default, Jul  2 2016, 17:42:40) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    Anaconda is brought to you by Continuum Analytics.
    Please check out: http://continuum.io/thanks and https://anaconda.org
    

    I have tried the solutions given in sol1

    Sol2

    I do not have sudo access to the server I can only use pip to install any module

  • Tamas Ionut
    Tamas Ionut over 6 years
    Installation of tensorflow works perfectly with Anaconda Navigator.
  • Schütze
    Schütze about 6 years
    It still says ImportError: No module named tensorflow
  • zhangjiangtao
    zhangjiangtao about 6 years
    Adding the path can be help for me.
  • Arthur Attout
    Arthur Attout over 5 years
    I tried it and it yielded Could not find a version that satisfies the requirement tensorflow (from versions: ) No matching distribution found for tensorflow
  • Dharma
    Dharma about 5 years
    I think you can try newer versions then. You can uninstall the previous one and do fresh install instead.
  • Ajp
    Ajp over 4 years
    This did it for me on Python 3.6
  • Adrien Pavao
    Adrien Pavao about 4 years
    Just use pip3 install instead of pip install.
  • Amogh Mishra
    Amogh Mishra about 4 years
    I had the same issue and it got resolved with this pip install tensorflow --ignore-installed --user
  • Woden
    Woden over 3 years
    I use @AmoghMishra's method and add the path in the environmental variables and it works!