[英]ModuleNotFoundError: No module named 'tensorflow', even when tensorflow is installed
I am trying to install tensorflow for one of my machine learning projects.我正在尝试为我的机器学习项目之一安装 tensorflow。 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:为了更好地说明这一点,我创建了一个test.py
文件,其内容如下:
import tensorflow as tf
print('Hello world!')
However, still the same error, on line 1.但是,仍然是相同的错误,在第 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 pip3 显示张量流
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: opensource@google.com
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 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 py 测试.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.特别感谢 Tensorflow Talk slack 中帮助过我的人,尤其是 @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.似乎它失败的原因之一是由于 tensorflow 的依赖项之一已过时/错误安装/某事。 The dependency is h5py
.依赖项是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).我通过尝试在 python 解释器(类型python
)中运行import tensorflow
发现了这一点,这给了我一个很长的堆栈跟踪,与测试文件不同(参见问题 2)。 I fixed this by reinstalling the dependency.我通过重新安装依赖项解决了这个问题。
Problem 2问题二
It turns out that I have 3, that's right, 3!原来我有3个,没错,3个! , versions of python on my computer , 我电脑上的python版本
python -V
---> 3.6.0 python -V
---> 3.6.0
python -V
(in an anaconda enviorment) ---> 3.6.7 python -V
(在蟒蛇环境中)---> 3.6.7
py -V
---> 3.7.0 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?我用py
运行我的测试文件,它显然是 3.7.0 (我认为它是python
同义词),我猜 tensorflow 不支持那个版本?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.