首页 > 解决方案 > tensorflow 在 anaconda 控制台中工作,在笔记本中失败:.ModuleNotFoundError: No module named 'tensorflow'

问题描述

遵循使用 anaconda 安装 tensorflow 的指南似乎可以作为:

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))

打印出你好。但笔记本中的相同代码得到:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-25b92e4d5dec> in <module>()
----> 1 import tensorflow as tf
      2 hello = tf.constant('Hello, TensorFlow!')
      3 sess = tf.Session()
      4 print(sess.run(hello))

ModuleNotFoundError: No module named 'tensorflow'

我在 acaconda 提示符中使用 jupyter notebook 启动了笔记本,上面写着:

(tensorflow) D:\ray\dev\ml\mit>

在我的一个用户目录中。

从 Windows 开始菜单启动 jupyter notebook 也失败了。

启动 jupyter notebook 的正确方法是什么?

标签: pythontensorflowanacondajupyter-notebook

解决方案


首先,激活您已tensorflow安装的 anaconda 环境。然后

conda install nb_conda

仍然在那个环境中,运行jupyter notebook


推荐阅读