未找到tensorflow模块(Jupyter笔记本中的Python 3.6.2从Anaconda 1.4.3 env打开,其中Tensorflow 1.2.1已安装pip; Win7 x64)

时间:2017-08-06 07:32:56

标签: python tensorflow anaconda

问题: 如何从Anaconda内部打开的Jupyter笔记本中导入Tensorflow?

我的环境: Anaconda 1.4.3, Python 3.6.2, Tensorflow 1.2.1和 Windows 7 x64。

背景: 从anaconda,我创建了一个环境“tensorflow_keras”,激活了所述环境,在其中安装了Tensorflow,并在命令行ipython中测试了Tensorflow。没有产生错误。

C:\Users\User1\Documents>activate tensorflow_keras

(tensorflow_keras) C:\Users\User1\Documents> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.1-cp36-cp36m-win_amd64.whl

(tensorflow_keras) C:\Users\User1\Documents>pip show tensorflow
Name: tensorflow
Version: 1.2.1
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: c:\program files\anaconda3\envs\tensorflow_keras\lib\site-packages
Requires: wheel, markdown, backports.weakref, werkzeug, six, protobuf, numpy, ht
ml5lib, bleach

(tensorflow_keras) C:\Users\User1\Documents>ipython
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 12:30:02) [MSC v
.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import tensorflow as tf

In [2]: node1 = tf.constant(3.0, dtype=tf.float32)

In [3]: print(node1)

Tensor("Const:0", shape=(), dtype=float32

然而,在Anaconda Navigator中,当我从安装Tensorflow的相同环境中打开Jupyter Notebook时,python命令

import tensorflow

引发了这个错误:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-a649b509054f> in <module>()
----> 1 import tensorflow

ModuleNotFoundError: No module named 'tensorflow'

Jupyter笔记本是从Anaconda内部的相同环境(“tensorflow_keras”)打开的,所以我假设这个程序也激活了所说的环境。

如何从Anaconda内部打开的Jupyter笔记本内导入Tensorflow?

提前感谢您的意见。

1 个答案:

答案 0 :(得分:0)

您可能需要在bash配置文件中解析Python PATH。请在Trouble with TensorFlow in Jupyter Notebook

查看问题和答案