循环导入tensorflow 2.4.1

Circular import tensorflow 2.4.1

我收到这个错误:

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

当我运行这个

import tensorflow as tf
from tensorflow import keras

import numpy as np
import matplotlib.pyplot as plt

fashion_mnist = keras.datasets.fashion_mnist

我在 Ubuntu.python 中使用 python 3.8.5 和 tensorflow 2.4.1。

有人有想法吗?

我想知道你的文件名是不是 'tensorflow.py'。如果是这种情况,您的文件将尝试导入您的文件本身,然后发生“(很可能是由于循环导入)”。