I am trying to install tensorflow for one of my machine learning projects. However, even though I have installed it, I still get this error
ModuleNotFoundError: No module named 'tensorflow'
To help illustrate this better, I have created a test.py file, with the following content:
import tensorflow as tf
print('Hello world!')
However, still the same error, on line 1.
Relevant questions:
I've tried doing many other answers, but none of them seems to help. Any answers would be appreciated.
Here's some debugging outputs that might help:
pip3 show tensorflow
Name: tensorflow
Version: 1.11.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: c:\program files\anaconda3\lib\site-packages
Requires: absl-py, termcolor, keras-applications, astor, six, tensorboard, keras-preprocessing, wheel, gast, setuptools, grpcio, protobuf, numpy
Required-by:
pip3 --version
pip 18.1 from c:\program files\anaconda3\lib\site-packages\pip (python 3.6)
python --version
Python 3.6.0 :: Anaconda 4.3.0 (64-bit)
py test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
I fixed it! Special thanks to the folks at the Tensorflow Talk slack who helped me, especially @akofman.
It was a combination of 2 problems:
Problem 1
It seems that one of the reasons it was failing was due to one of tensorflow's dependencies being outdated/misinstalled/something. The dependency is h5py. I found out about this by attempting to run import tensorflow in the python interpreter (type python), which gave me a long stack trace, unlike the test file (see problem 2). I fixed this by reinstalling the dependency.
Problem 2
It turns out that I have 3, that's right, 3!, versions of python on my computer
python -V ---> 3.6.0
python -V (in an anaconda enviorment) ---> 3.6.7
py -V ---> 3.7.0
I was running my test file with py, which is apparently 3.7.0 (I thought it was synonymous with python), I guess tensorflow doesn't support that version?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With