Circular import tensorflow 2.4.1

Viewed 253

I am getting this error:

ImportError: cannot import name 'keras' from partially initialized module 'tensorflow' (most likely due to a circular import)

when I run this

import tensorflow as tf
from tensorflow import keras

import numpy as np
import matplotlib.pyplot as plt

fashion_mnist = keras.datasets.fashion_mnist

I am using python 3.8.5 and tensorflow 2.4.1 in Ubuntu.

Anyone has an idea?

1 Answers

I'm wondering if your file name is 'tensorflow.py'. If that the case, your file will attempt to import your file itself and then '(most likely due to a circular import)' occurs.

Related