keep-loving-pythonのブログ

Pythonを愛し続けたいです(Pythonが流行っている限りですが。。。)

解決策。ImportError: cannot import name 'naming' from 'tensorflow.python.autograph.core'。

エラー

環境

windows10
python3.7

エラー

ImportError: cannot import name 'naming' from 'tensorflow.python.autograph.core'
cannot import name 'naming' from 'tensorflow.python.autograph.core'

エラー詳細

>python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from transformers import pipeline
2023-05-01 19:42:12.295722: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2023-05-01 19:42:12.310752: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\utils\import_utils.py", line 1146, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\pipelines\__init__.py", line 68, in <module>
    from .table_question_answering import TableQuestionAnsweringArgumentHandler, TableQuestionAnsweringPipeline
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\pipelines\table_question_answering.py", line 26, in <module>
    import tensorflow_probability as tfp
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_probability\__init__.py", line 75, in <module>
    from tensorflow_probability.python import *  # pylint: disable=wildcard-import
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_probability\python\__init__.py", line 24, in <module>
    from tensorflow_probability.python import experimental
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_probability\python\experimental\__init__.py", line 34, in <module>
    from tensorflow_probability.python.experimental import auto_batching
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_probability\python\experimental\auto_batching\__init__.py", line 24, in <module>
    from tensorflow_probability.python.experimental.auto_batching import frontend
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_probability\python\experimental\auto_batching\frontend.py", line 44, in <module>
    from tensorflow.python.autograph.core import naming
ImportError: cannot import name 'naming' from 'tensorflow.python.autograph.core' (C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\autograph\core\__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1032, in _handle_fromlist
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\utils\import_utils.py", line 1136, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\utils\import_utils.py", line 1151, in _get_module
    ) from e
RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback):
cannot import name 'naming' from 'tensorflow.python.autograph.core' (C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\autograph\core\__init__.py)
>>>

解決策

すみません、どれが有効打か、ちょっと、不正確。

python -m pip install tensorflow-probability==0.7.0

↓ もしかすると、これも関係するかも。。。

python -m pip install tfp-nightly==0.11.0.dev20200708

現状のモジュール構成

↓ どれが意味があるのか、よくわかっていません。

keras                             2.11.0

tensorflow                        2.3.1

tensorflow-probability            0.7.0

tfp-nightly                       0.11.0.dev20200708

torch                             1.10.2

transformers                      4.28.1

コメント

すっきりした情報あれば、コメントで教えて下さい!!!是非!!!