简体   繁体   中英

tensorflow import error: No module named tensorflowin Jupyter with Python 2.7

update: I tried to uninstall and reinstall tensorflow. It worked in command line but in Jupyter, it shows:

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

ImportError: No module named tensorflow

I checked where tensorflow is installed (it seems to be in the correct location, but I still cannot successfully import tensorflow in juypter):

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

I installed tensorflow in the past and it worked well in Jupyter. But there was one time that I tried to install keras, and then tensorflow began to have some issues. I tried to import tensorflow as tf in Juypter today, but I encountered the following import error.

=============== earlier error is below and now changed to the error above ==============

---------------------------------------------------------------------------
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

I tried to search around but could not find an answer that solved this issue.

I tried but it says requirement already satisfied:

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

Any insights will be greatly appreciated!

Make sure you are in the right environment when you install modules.

conda install tensorflow

installing-python-packages-from-jupyter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM