3

I am writing the following code in Jupyter notebook.

import tensorflow as tf
g = tf.Graph()

And I encounter the following error while executing this simple code.

AttributeError: module 'tensorflow' has no attribute 'Graph'

If I execute the same from the console. It works. Any idea what's happening here.

More information:(test is my virtualenv)

ipython, jupyter, python version:

(test) xingzhou@xingzhou008:~/tensorflow$ which ipython3
/home/xingzhou/tensorflow/test/bin/ipython3
(test) xingzhou@xingzhou008:~/tensorflow$ which jupyter
/home/xingzhou/tensorflow/test/bin/jupyter
(test) xingzhou@xingzhou008:~/tensorflow$ which python3
/home/xingzhou/tensorflow/test/bin/python3

Execute from Console:

(test) xingzhou@xingzhou008:~/tensorflow$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> g = tf.Graph()
>>> type(g)
<class 'tensorflow.python.framework.ops.Graph'>
>>> 
1

4 Answers 4

3

Make sure you haven't called any of your python files as 'tensorflow.py'

Sign up to request clarification or add additional context in comments.

Comments

2

I resolved this issue by restarting Jupyter Notebook kernel. It's weird.

Comments

1

A simple solution worked for me. From anaconda navigator first go to environments and create a tensorflow environment like this image

enter image description here

I named it tensorflow. Then from the right select all from the drop down menu and search for tensorflow.

enter image description here

Select it and hit apply. It will download some additional packages along with tensorflow. When you are done, select tensorflow from home and you should be good to go. Here it works.

enter image description here

Comments

0

Check if TensorFlow is installed in Anaconda/Environments. If not, just search and install. Then try to run g=tf.Graph() again. It worked for me.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.