[Python] TypeError: __init__() got an unexpected keyword argument 'metaclass'

Discussão em 'Python' iniciado por Stack, Dezembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    When I use python 3.9 in pycharm and try to import packages, I get the error. The problem occurs after running to the second line of code:

    import tensorflow as tf
    from tensorflow.keras.models import Sequential


    This is the output from the console

    D:\Download\anaconda3\envs\py39\python.exe "D:/Download/JetBrains/PyCharm 2023.1.2/plugins/python/helpers/pydev/pydevd.py" --multiprocess --qt-support=auto --client 127.0.0.1 --port 11881 --file "D:\proj2\Demo code.py"
    Connected to pydev debugger (build 231.9011.38)
    2023-11-27 18:20:56.514016: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
    WARNING:tensorflow:From D:\Download\anaconda3\envs\py39\lib\site-packages\keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.
    2023-11-27 18:21:08.537061: W external/local_tsl/tsl/lib/monitoring/collection_registry.cc:81] Trying to register 2 metrics with the same name: /tensorflow/api/keras/optimizers. The old value will be erased in order to register a new one. Please check if you link the metric more than once, or if the name is already used by other metrics.
    Traceback (most recent call last):
    File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
    File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 850, in exec_module
    File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
    File "D:\Download\anaconda3\envs\py39\lib\site-packages\tensorflow\__init__.py", line 485, in <module>
    importlib.import_module("keras.src.optimizers")
    File "D:\Download\anaconda3\envs\py39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "D:\Download\anaconda3\envs\py39\lib\site-packages\keras\__init__.py", line 20, in <module>
    from keras import distribute
    File "D:\Download\anaconda3\envs\py39\lib\site-packages\keras\distribute\__init__.py", line 18, in <module>
    from keras.distribute import sidecar_evaluator
    File "D:\Download\anaconda3\envs\py39\lib\site-packages\keras\distribute\sidecar_evaluator.py", line 22, in <module>
    from keras.optimizers.optimizer_experimental import (
    File "D:\Download\anaconda3\envs\py39\lib\site-packages\keras\optimizers\__init__.py", line 26, in <module>
    from keras.optimizers.legacy import adadelta as adadelta_legacy
    File "D:\Download\anaconda3\envs\py39\lib\site-packages\keras\optimizers\legacy\adadelta.py", line 17, in <module>
    from keras.optimizers.optimizer_v2 import adadelta
    File "D:\Download\anaconda3\envs\py39\lib\site-packages\keras\optimizers\optimizer_v2\adadelta.py", line 21, in <module>
    from keras.optimizers.optimizer_v2 import optimizer_v2
    File "D:\Download\anaconda3\envs\py39\lib\site-packages\keras\optimizers\optimizer_v2\optimizer_v2.py", line 103, in <module>
    @keras_export("keras.optimizers.Optimizer", metaclass=abc.ABCMeta)
    TypeError: __init__() got an unexpected keyword argument 'metaclass'
    python-BaseException


    I tried to bring tensorflow up to date


    conda install tensorflow
    ​

    Continue reading...

Compartilhe esta Página