Python ModuleNotFoundError:没有名为“tensorflow”的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42970106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 22:18:54  来源:igfitidea点击:

ModuleNotFoundError: No module named 'tensorflow'

pythontensorflowjupyterspyder

提问by pavan U

When I'm importing TensorFlow with Spyder as so:

当我使用 Spyder 导入 TensorFlow 时:

import tensorflow as tf

I then face the following error:

然后我面临以下错误:

ModuleNotFoundError: No module named 'tensorflow'

ModuleNotFoundError:没有名为“tensorflow”的模块

How can I overcome this issue?

我怎样才能克服这个问题?

回答by Tom

Since you plan to use tensforflow with Anaconda, you need to install it through Anaconda. It is advisable to do this as follows:

由于您计划将 tensforflow 与 Anaconda 一起使用,因此您需要通过 Anaconda 安装它。建议按以下方式执行此操作:

  1. C:> conda create -n tensorflow
  2. C:> activate tensorflow
  3. C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.1-cp35-cp35m-win_amd64.whl
  1. C:> conda create -n tensorflow
  2. C:> activate tensorflow
  3. C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.1-cp35-cp35m-win_amd64.whl

It is recommended you create a virtual environment as shown above as this makes managing different versions of Python easier. All packages you install (in this case Tensorflow) will become available whenever you activate this virtual environment, and they will not conflict with other versions of Python you may have.

建议您创建一个如上所示的虚拟环境,因为这样可以更轻松地管理不同版本的 Python。每当您激活此虚拟环境时,您安装的所有软件包(在本例中为 Tensorflow)都将可用,并且它们不会与您可能拥有的其他 Python 版本冲突。