114

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: opensource@google.com
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

Community
  • 1
  • 1
Abhishek Gangwar
  • 1,697
  • 3
  • 17
  • 29

23 Answers23

57

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.

Dharma
  • 2,425
  • 3
  • 26
  • 40
  • 14
    I tried it and it yielded `Could not find a version that satisfies the requirement tensorflow (from versions: ) No matching distribution found for tensorflow` – Arthur Attout Dec 07 '18 at 11:06
  • 1
    I think you can try newer versions then. You can uninstall the previous one and do fresh install instead. – Dharma Mar 27 '19 at 08:36
  • 7
    I had the same issue and it got resolved with this `pip install tensorflow --ignore-installed --user` – Amogh Mishra May 02 '20 at 19:51
  • 1
    I use @AmoghMishra's method and add the path in the environmental variables and it works! – Woden Sep 26 '20 at 10:43
34

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.

Cryptc
  • 2,959
  • 1
  • 18
  • 18
31

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: opensource@google.com
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.
Alpa8
  • 470
  • 4
  • 12
27

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

R Dragon
  • 981
  • 8
  • 9
12

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

pip install tensorflow --user

Vijay
  • 1,030
  • 11
  • 34
10

You may need this since first one may not work.

python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

Musakkhir Sayyed
  • 7,012
  • 13
  • 42
  • 65
parlad
  • 1,143
  • 4
  • 23
  • 42
10

you might wanna try this:

$conda install -c conda-forge tensorflow
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Pallavi Kalambe
  • 793
  • 8
  • 7
6

with python2

pip show tensorflow to check install

python test.py to run test

with python3

pip3 show tensorflow to check install

python3 test.py to run test

test.py

import tensorflow as tf
import numpy as np

c = np.array([[3.,4], [5.,6], [6.,7]])
step = tf.reduce_mean(c, 1)                                                                                 
with tf.Session() as sess:
    print(sess.run(step))

Or, if you haven't install tensorflow yet, try the offical document

KunMing Xie
  • 1,613
  • 17
  • 15
6

For me, if I did

python3 -m pip install tensorflow

then I got the error the OP reports when using a 3rd party library calling tensorflow.

However, when I substituted either tensorflow-cpu or tensorflow-gpu (depending upon which one is appropriate for you) then the code was suddenly able to find tensorflow.

demongolem
  • 9,474
  • 36
  • 90
  • 105
4

I was trying to install tensorflow GPU for a Windows 7 with pip3 for python3.5.x. Instead of doing pip3 install --upgrade tensorflow I just did pip install tensorflow and after it completed i was finally able to import tensorflow in python3.5.x.

3

So, your problem is that you are using the wrong commands. If you install it with python3 -m pip install tensorflow, then it will install for Python3. Not any other types like py, or python.

Your solution: Run these commands:

  1. python3 -m pip install tensorflow
  2. python -m pip install tensorflow
  3. py -m pip install tensorflow
Anthony
  • 73
  • 9
1

Instead of using the doc's command (conda create -n tensorflow pip python=2.7 # or python=3.3, etc.) which wanted to install python2.7 in the conda environment, and kept erroring out saying the module can't be found when following the installation validation steps, I used conda create -n tensorflow pip python=3 to make sure python3 was installed in the environment.

Doing this, I only had to type python instead of python3 when validating the installation and the error went away.

Mike_2161
  • 11
  • 2
1

If you remove all underscores in the jupyter notebook file name, it should start working. No idea why.

For example, test.ipynb could import tensorflow, but test_test.ipynb couldn't.

If you're like me, you created a jupyter notebook file (.ipynb) and couldn't import tensorflow even though it installed properly.

This problem didn't occur with normal python files (.py), regardless of whether they had underscores in their names or not.

I'm using vscode if that matters.

seth
  • 63
  • 1
  • 2
  • 8
0

Try Anaconda install steps from TensorFlow docs.

Vitalie Maldur
  • 553
  • 3
  • 19
0

Activate the virtualenv environment by issuing one of the following commands:

$ source ~/tensorflow/bin/activate # bash, sh, ksh, or zsh
$ source ~/tensorflow/bin/activate.csh # csh or tcsh

Hope this help

amy
  • 1
0

This Worked for me:

$ sudo easy_install pip
$ sudo easy_install --upgrade six
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py2-none-any.whl
$ sudo pip install --upgrade $TF_BINARY_URL
FelixSFD
  • 6,052
  • 10
  • 43
  • 117
0

I had exactly the same problem. It's because default python is in version 2 You need to link to the version 3.

>sudo rm -rf /usr/bin/python
>sudo ln -s /usr/bin/python3.5 /usr/bin/python

python links

Kcm
  • 138
  • 7
0

I ran into the same issue. I simply updated my command to begin with python3 instead of python and it worked perfectly.

Jonathan
  • 648
  • 4
  • 13
  • 34
0

In my case, I install 32 Bit Python so I cannot install Tensorflow, After uninstall 32 Bit Python and install 64 Bit Python, I can install tensorflow successfully.

After reinstall Python 64 bit, you need to check your python install folder path is properly set in Windows Environment Path.

You can check Python version by typing python in cmd.

yu yang Jian
  • 6,680
  • 7
  • 55
  • 80
0

On my remote machine, I had TensorFlow installed via pip and when I was importing it in ipython the import was successful. Despite of that I still got the No module named tensorflow error when I was running my scripts. The issue here was that I was running my scripts with sudo, so the python and tensorflow paths were not visible to the root. When I ran my scripts without sudo, everything worked.

tsveti_iko
  • 6,834
  • 3
  • 47
  • 39
0

My experience.

A, check your python version, in my case python 3.6

B, use the command: python3.6 myscript.py;

C, my tensorflow version is 1.10

quine9997
  • 685
  • 7
  • 13
0

It's a bit late answer, but I guess might be a common one. I had encountered the same problem and neither of the proposed methods in here worked for my case, Python v3.7 and working on a Linux server. I tested the following command line and it worked for me:

python3 -m pip install tensorflow
0

More details here: https://appuals.com/could-not-find-a-version-that-satisfies-the-requirement-for-tensorflow/

pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl