tensorflow: ImportError: No module named tensorflow - Can't install Tensorflow

I am trying to install tensorflow on mac and it’s giving me this error.

ImportError: No module named tensorflow

Here is what I have done in the terminal

`sudo easy_install pip

sudo easy_install --upgrade six export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py3-none-any.whl sudo -H pip3 install --upgrade $TF_BINARY_URL`

After that I try to run python and tensorflow to check my installation. It doesn’t work. I have spent 3 hours on the problem.

Here is another post about it. http://stackoverflow.com/questions/40472144/importerror-no-module-named-tensorflow-cant-install-tensorflow?noredirect=1#comment68200554_40472144

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 22 (3 by maintainers)

Most upvoted comments

i had the same issue. and here is why it happen and how i fixed it in my issue: env: anaconda (python 3.6)+mac , first ,i used : $ pip3 install tensorflow $ python Python 3.6.0 |Anaconda 4.3.0 (x86_64)| (default, Dec 23 2016, 13:19:00)

import tensorflow as tf

ModuleNotFoundError: No module named ‘tensorflow’

and then $pip install tensorflow $python Python 3.6.0 |Anaconda 4.3.0 (x86_64)| (default, Dec 23 2016, 13:19:00)

import tensorflow as tf

I had the same issue with mac os… this fixed the problem: install brew brew install python 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

Please consider these things:

  • What OS? We support El Capitan right now. Sierra hopefully soon.
  • Try a newer version than 0.9 which is quite old, perhaps 0.11rc2
  • Are there any errors on the pip install?
  • What version of python. Perhaps try the python 2 version if you have that as well. Show exactly what version of python you are actually running and what it spits out. For example…
$ python
Python 2.7.10 (default, Jul 30 2016, 18:31:42) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named tensorflow
>>> 

I understand it is frustrating to spend 3 hours having trouble, but it is hard for us to help you when you do not provide detailed information. Thanks.

If you use brew:

  • brew install python - installs 2.7
  • brew install python3 - installs 3.6 in any case, you are not running optimal version for TensorFlow 3.5

Anyway, $ python --version Python 3.5.2 :: Continuum Analytics, Inc.

$ echo $TF_BINARY_URL https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.1-py3-none-any.whl

When running: $ sudo pip3 install --ignore-installed --upgrade $TF_BINARY_URL

it looks like it installs everything 100% $ conda list … tensorflow-gpu 0.12.1 <pip> …

but when running $ jupyter notebook import tensorflow as tf ModuleNotFoundError: No module named ‘tensorflow’

For Jupyter kernel to reflect changes in conda env (tensorflow), I had to set up the following:

$ source activate tensorflow
$ sudo pip install ipykernel
$ python -m ipykernel install --user --name tensorflow --display-name "conda env tensorflow"

my blog

卧槽 解决了 很给力!

わあ、解決し、すごい

Hi @aselle ,

THIS IS SOLVED, SEE BOTTOM COMMENT I am having the same error too. I am using EI Capitan 10.11.2

Here is what i did in my installation, no error during the installation:

$ 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

Here is my tensor flow information:

$ pip show tensorflow
Name: tensorflow
Version: 0.9.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: /usr/local/lib/python2.7/site-packages
Requires: protobuf, numpy, wheel, six

here is my protobuf information:

$ pip show protobuf
Name: protobuf
Version: 3.0.0b2
Summary: Protocol Buffers
Home-page: https://developers.google.com/protocol-buffers/
Author: protobuf@googlegroups.com
Author-email: protobuf@googlegroups.com
License: New BSD License
Location: /usr/local/lib/python2.7/site-packages
Requires: setuptools, six

here is my six information:

$ pip show six
Name: six
Version: 1.10.0
Summary: Python 2 and 3 compatibility utilities
Home-page: http://pypi.python.org/pypi/six/
Author: Benjamin Peterson
Author-email: benjamin@python.org
License: MIT
Location: /usr/local/lib/python2.7/site-packages
Requires:

Following is my python version:

$ python
Python 2.7.10 (default, Oct 23 2015, 18:05:06)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensor flow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named tensor flow
>>>

UPDATE: It seems that my pip is link to python 2.7.12 (previously installed via Homebrew). I uninstall everything, and reinstall to solve the issue

I have another stituation, I have succssfully installed tensorflow on my mac, and a function which uses tensorflow’s model can run by its own. However, when I import this fuction in Django, the first line is ‘import tensorflow as tf’, error: ModuleNotFoundError: No module named ‘tensorflow’… wtf

I create a virtual environment, when I run some codes ,give the same Error. And I reinstall tensorflow , but it doesn’t work

@Afrogeek254 I also stumbled on this problem, and fixed it by changing python version. (Win10 x64) Funny thing is that the first version I tried is the one “supported” by TF as said in the documentation (used the link in the page for 3.6.x 64 which was 3.6.2). Didn’t want to find a workaround, and ended up installing 3.5.2 (also linked in the installation docs)

i had the same issue. i installed two version of python 2.7 and 3.5 tensorflow installs in python2.7

my default python version is 3.5 so if I type: python Python 3.5.3 (default, Dec 7 2017, 09:41:57) [GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux 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’

but if I type: python2.7 Python 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information.

import tensorflow as tf

It`s OK

so check your python version. It will help

chunchuria umbrella