In this TensorFlow tutorial, I will show you how to resolve the error **Attributeerror: Module ‘tensorflow’ has no attribute ‘log’**.

I will explain three approaches to solving that error: **downgrade the tensorflow version**, use the **compatibility mode**, and use the **tf.math** submodule of TensorFlow version 2 to fix the error.

Let’s solve the error,

## Attributeerror: Module ‘tensorflow’ has no attribute ‘log’

The error **Attributeerror: Module ‘tensorflow’ has no attribute ‘log’**, which says you are trying to access the attribute log from the TensorFlow library, which doesn’t exist.

- The tensorflow supports several elementary mathematical operations. The Tensorflow function
**tf.log()**supports the natural logarithmic function. It anticipates input as floating point values or complex numbers in the**a+bi**format.

Let me show you the cause of the error. Run the code below.

```
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
new_tens = tf.constant([-2.3, -5.3, 1.7, 1.4, 9], dtype = tf.float32)
result= tf.log(new_tens)
with tf.Session() as val:
new_output=val.run(result)
print(new_output)
```

The **error appears when you directly access TensorFlow’s attribute log()**. Your code is correct here, but you use it in the tensorFlow version 2 environment. This means that in TensorFlow version 1, you can directly access the log() from the library.

However, this is not possible in the TensorFlow 2 because of the change in the API. In simpler words, your code is based on TensorFlow version 1, and you have updated tensorflow version 2 and then ran this code, which is invalid for TensorFlow 2.

You have three options to solve that error: **either downgrade the TensorFlow version, use the tensorflow 1 compatibility mode in the TensorFlow version 2 environment**, or **use the latest API method of TensorFlow 2.**

Let’s look at each solution one by one.

First, create a separate environment that env installs a specific version of TensorFlow, such as **version 1.13 or 1.4**, etc.

`pip install -upgrade tensorflow==1.13`

After downgrading, when you run the code, it doesn’t show the error.

The next solution is to use TensorFlow version 1 in the current environment version 2 using the **tf.compat.v1** module.

```
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
new_tens = tf.constant([-2.3, -5.3, 1.7, 1.4, 9], dtype = tf.float32)
result= tf.compat.v1.log(new_tens)
with tf.compat.v1.Session() as val:
new_output=val.run(result)
print(new_output)
```

Using the **tf.compat.v1** module, you have successfully accessed the log() function in the TensorFlow version 2 environment.

Finally, you can use the submodule **tf.math** to access the **log()** attribute; in the latest version of tensorflow, all the mathematical functions have been moved to the submodule tf.math.

So, rerun the code but access the log() attribute from the tf.math submodule, as shown in the code below.

```
import tensorflow as tf
new_tens = tf.constant([-2.3, -5.3, 1.7, 1.4, 9], dtype = tf.float32)
result= tf.math.log(new_tens)
print(result.numpy())
```

In the above code, **accessing the log() attribute from the tf.math**, you also don’t need to use session; in the TensorFlow 2, this session is handled by default. As a result, you don’t get that error again.

The above approach is a recommended solution that you should follow to avoid errors in future.

This is how to fix the error **Attributeerror: Module ‘tensorflow’ has no attribute ‘log’** in TensorFlow.

## Conclusion

In this TensorFlow tutorial, you fixed the error **Attributeerror: Module ‘tensorflow’ has no attribute ‘log’.**

You solved the error using three different methods: downgrading the tensorflow version and using the tf. compact.v1 module and by using the tf.math submodule.

You may like to read:

- Attributeerror: Module ‘tensorflow’ has no attribute ‘global_variables_initializer’
- Attributeerror: Module ‘tensorflow’ has no attribute ‘truncated_normal_initializer’
- Attributeerror: Module ‘tensorflow’ has no attribute ‘trainable_variables’

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.