tensorflow导入错误:在使用Python 2.7的Jupyter中没有名为tensorflow的模块

时间:2018-09-18 00:51:00

标签: python tensorflow anaconda jupyter-notebook

更新: 我试图卸载并重新安装tensorflow。它在命令行中有效,但在Jupyter中显示:

ImportError                               Traceback (most recent call last)
<ipython-input-14-40bf8ae976e6> in <module>()
----> 1 import tensorflow

ImportError: No module named tensorflow

我检查了tensorflow的安装位置(它似乎在正确的位置,但是我仍然无法在juypter中成功导入tensorflow):

pip show tensorflow
-bash: syntax error near unexpected token `pip'
 (tensorflow) LPT-010557-PU:~ lzhang22$ pip show tensorflow
Name: tensorflow
Version: 1.10.1
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: /anaconda2/envs/tensorflow/lib/python2.7/site-packages
Requires: astor, tensorboard, setuptools, gast, enum34, protobuf, six, absl-py, backports.weakref, wheel, termcolor, numpy, mock, grpcio

我过去安装了tensorflow,在Jupyter中运行良好。但是有一段时间我尝试安装keras,然后tensorflow开始出现一些问题。我今天尝试在Juypter中将tensorflow导入为tf,但是遇到以下导入错误。

================以前的错误在下面,现在变为上面的错误=============

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-4-41389fad42b5> in <module>()
----> 1 import tensorflow as tf

/anaconda2/lib/python2.7/site-packages/tensorflow/__init__.py in <module>()
 20 
 21 # pylint: disable=g-bad-import-order
---> 22 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
 23 
 24 try:

/anaconda2/lib/python2.7/site-packages/tensorflow/python/__init__.py in <module>()
 47 import numpy as np
 48 
---> 49 from tensorflow.python import pywrap_tensorflow
 50 
 51 # Protocol buffers

ImportError: cannot import name pywrap_tensorflow

我试图四处搜寻,但找不到解决此问题的答案。

我尝试过,但说要求已经满足:

pip install tensorflow 
Requirement already satisfied: tensorflow in /anaconda2/lib/python2.7/site-packages (1.10.1)

任何见解将不胜感激!

1 个答案:

答案 0 :(得分:0)

在安装模块时,请确保您处于正确的环境中。

conda install tensorflow

installing-python-packages-from-jupyter