2

Question: How can I import Tensorflow from inside a Jupyter Notebook opened from inside Anaconda?

My environment: Anaconda 1.4.3, Python 3.6.2, Tensorflow 1.2.1 and Windows 7 x64.

Background: From anaconda, I created an environment "tensorflow_keras", activated said environment, installed Tensorflow within it, and tested Tensorflow from within command line ipython. No errors were generated.

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

However, inside Anaconda Navigator, when I open a Jupyter Notebook from the same environment where Tensorflow was installed, the python command

import tensorflow

raises this error:

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

ModuleNotFoundError: No module named 'tensorflow'

The Jupyter Notebook was opened from the same environment ("tensorflow_keras") from inside Anaconda, so I assumed this procedure also activates said environment.

How can I import Tensorflow from inside a Jupyter Notebook opened from inside Anaconda?

Thanks in advance for your inputs.

fairnc
  • 121
  • 1
  • 3

1 Answers1

0

You may need to resolve the Python PATH in your bash profile. Please see question and responses at Trouble with TensorFlow in Jupyter Notebook

Andrew B
  • 1
  • 2