Attributeerror: module tensorflow has no attribute app error occurs because of version incompatibility between tensorflow versions. Actually, TesnorFlow community maintains two versions of TensorFlow 1. x series and 2. x series. There are too many syntax differences in both versions. Some are too drastic as well which is breaking the code as well like the above error. Few changes are impacting as a warning such as performance etc which we can ignore. Anyways in this article, we will explore the best way to fix this error.
Attributeerror: module tensorflow has no attribute app ( Solution ) –
This problem is easy to solve either you downgrade the interpreter’s tensorflow version or make your current code compatible with existing tensorflow version 2.0. The second one seams lengthy but more safe than first. Because if you downgrade the ternsorflow version to fix a single Attributeerror, You may end with tons of errors. Well, let’s address the solution differently.
Solution 1: Using import tensorflow.compat.v1 as tf –
Suppose your interpreter has tensorflow 2.x version install but you code entirely or subsection is on tensorflow 1.x then for that subsection you can import tensorflow as below –
import tensorflow.compat.v1 as tf
It will give backward compatibility.
Solution 2: Using tf.compat.v1.flags –
If your complete code if fine and compatible with tensorFlow but somehow one or two lines are breaking because of this app attribute then only in this case, you should try
In the place of ( incorrect )
Solution 3 – Converting tensorFlow 1.x code to 2.x code –
Suppose one of your utilities is completely on tensorFlow 1. x and the rest of the project or utility is entirely in tensorFlow 2.x. In this case, you should try this trick. Since a major part of your code is in tensorflow 2.x, Hence we will convert the code to the 1. x oriented code in 2. x version.
tf_upgrade_v2 \ --intree code_1.x/ \ --outtree code_2.x/ \ --reportfile log.txt
Similar Errors –
1.Attributeerror: module ‘tensorflow’ has no attribute configproto
2. Attributeerror module tensorflow has no attribute get_default_graph
3.Attributeerror module tensorflow has no attribute gfile ( Solved )
4.Attributeerror: module tensorflow has no attribute placeholder
5.Attributeerror: module ‘tensorflow’ has no attribute ‘session’
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.