Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'>
>>> 
like image 855
Xing Zhou Avatar asked Feb 02 '26 01:02

Xing Zhou


2 Answers

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

like image 179
TomV Avatar answered Feb 04 '26 01:02

TomV


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

like image 26
Xing Zhou Avatar answered Feb 04 '26 01:02

Xing Zhou