简体   繁体   中英

AttributeError: keras.backend ,no attribute 'eager'

I'm using python 3.8.2, keras 2.3.1 and tensorflow 2.2.0rc4. just with the following code:

import keras
from keras.models import sequential

I have this error: AttributeError: partially initialized module 'keras.backend' has no attribute 'eager' (most likely due to a circular import)

if I use:

import tensorflow

or

from tensorflow.keras import ....

new error:

AttributeError: partially initialized module 'tensorflow.python.framework.ops' has no attribute 'register_tensor_conversion_function' (most likely due to a circular import)

full traceback: enter image description here

enter image description here

My suggestion is to reinstall the package. Sometimes this happens due to the installation problem.

Use the following code to do so

Uninstall tensorflow

pip uninstall tensorflow

Requires the latest pip

pip install --upgrade pip

To install keras as separate package

pip install Keras

Current stable release for CPU and GPU

pip install tensorflow

Try this and hope this helps you.

It's an install problem, most likely; K.eager was introduced in Keras 2.3.0 (and is included in Keras 2.3.1), so your Python interpreter is somehow reading code of 2.2.5 or earlier.

A possible culprit is an Anaconda mishap. First run conda uninstall keras . Then, in the anaconda3 directory, search "keras" and delete all results. Lastly, run conda install -c conda-forge keras , which should download version 2.3.1. You might need to run similar steps with TensorFlow (in fact, it's better you do , and first reinstall TensorFlow then Keras).

PS, your code is probably from keras import Sequential , as sequential should error differently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM