Steven Barkin
Steven Barkin

Reputation: 99

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

In MacOS, I used Pip to install tensorflow following the standard instructions on the tensorflow.org website.

When I start Spyder, I am able to execute the following instruction without error:

import tensorflow as tf

But when I attempt to run the following instruction: g = tf.Graph(), I get the following error:

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

When I do the same in "python" or "ipython" instead of Spyder, I do not get this error. But I would like to use Spyder.

I tried the install with Conda instead of Pip, but got the same symptoms.

Upvotes: 1

Views: 11552

Answers (2)

momo
momo

Reputation: 1122

For anyone coming in recent times, this error might come up when using Keras. Solved it by changing all

from keras.something import something

to

from tensorflow.keras.something import something

Can see github issue about this.

Upvotes: 1

vinjohn
vinjohn

Reputation: 26

These steps worked for me: (linux, pip, tf1.4-gpu)

  • Uninstall tensorflow pip uninstall tensorflow-gpu
  • Delete pip caches rm -rf ~/.cache/pip/*
  • Re-install tensorflow pip install -U tensorflow-gpu

Upvotes: 1

Related Questions