简体   繁体   English

Python 导入错误 Tensorflow 2. Keras

[英]Python error in importing Tensorflow 2 . Keras

I did write some deep learning code sometimes ago.Now I want to run it again.我以前确实写过一些深度学习代码。现在我想再次运行它。 But at first it gave me these errors.但起初它给了我这些错误。 here is the first block of code that went into a problem:这是出现问题的第一个代码块:

import tensorflow.keras
from tensorflow.keras import layers
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation,Flatten,MaxPooling2D,Conv2D
from tensorflow.keras.utils import to_categorical

and here is the error:这是错误:

ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.

ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.

ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.

this is the Traceback error:这是回溯错误:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-177d4802053d>", line 1, in <module>
    import tensorflow.keras
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
    from tensorflow_core import *
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Users\msi-pc\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\python\__init__.py", line 64, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\core\framework\graph_pb2.py", line 7, in <module>
    from google.protobuf import descriptor as _descriptor
ImportError: cannot import name 'descriptor' from 'google.protobuf' (unknown location)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 2045, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'ImportError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1170, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 316, in wrapped
    return f(*args, **kwargs)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 350, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 1502, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 1460, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 696, in getsourcefile
    if getattr(getmodule(object, filename), '__loader__', None) is not None:
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 733, in getmodule
    if ismodule(module) and hasattr(module, '__file__'):
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Users\msi-pc\Anaconda3\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 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  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\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\__init__.py", line 42, in <module>
    from . _api.v2 import audio
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\_api\v2\audio\__init__.py", line 10, in <module>
    from tensorflow.python.ops.gen_audio_ops import decode_wav
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\python\ops\gen_audio_ops.py", line 10, in <module>
    from tensorflow.python.eager import context as _context
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\python\eager\context.py", line 25, in <module>
    from absl import logging
ModuleNotFoundError: No module named 'absl'
Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-177d4802053d>", line 1, in <module>
    import tensorflow.keras
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
    from tensorflow_core import *
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Users\msi-pc\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\python\__init__.py", line 64, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\core\framework\graph_pb2.py", line 7, in <module>
    from google.protobuf import descriptor as _descriptor
ImportError: cannot import name 'descriptor' from 'google.protobuf' (unknown location)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 2045, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'ImportError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 3338, in run_ast_nodes
    if (await self.run_code(code, result,  async_=asy)):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 3435, in run_code
    self.showtraceback(running_compiled_code=True)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 2048, in showtraceback
    value, tb, tb_offset=tb_offset)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1437, in structured_traceback
    self, etype, value, tb, tb_offset, number_of_lines_of_context)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1337, in structured_traceback
    self, etype, value, tb, tb_offset, number_of_lines_of_context
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1194, in structured_traceback
    tb_offset)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1151, in format_exception_as_a_whole
    last_unique, recursion_repeat = find_recursion(orig_etype, evalue, records)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 451, in find_recursion
    return len(records), 0
TypeError: object of type 'NoneType' has no len()

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 2045, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'TypeError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1170, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 316, in wrapped
    return f(*args, **kwargs)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 350, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 1502, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 1460, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 696, in getsourcefile
    if getattr(getmodule(object, filename), '__loader__', None) is not None:
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 733, in getmodule
    if ismodule(module) and hasattr(module, '__file__'):
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Users\msi-pc\Anaconda3\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 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  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\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\__init__.py", line 42, in <module>
    from . _api.v2 import audio
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\_api\v2\audio\__init__.py", line 10, in <module>
    from tensorflow.python.ops.gen_audio_ops import decode_wav
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\python\ops\gen_audio_ops.py", line 10, in <module>
    from tensorflow.python.eager import context as _context
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\python\eager\context.py", line 25, in <module>
    from absl import logging
ModuleNotFoundError: No module named 'absl'
Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-177d4802053d>", line 1, in <module>
    import tensorflow.keras
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
    from tensorflow_core import *
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Users\msi-pc\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\python\__init__.py", line 64, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\core\framework\graph_pb2.py", line 7, in <module>
    from google.protobuf import descriptor as _descriptor
ImportError: cannot import name 'descriptor' from 'google.protobuf' (unknown location)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 2045, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'ImportError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 3338, in run_ast_nodes
    if (await self.run_code(code, result,  async_=asy)):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 3435, in run_code
    self.showtraceback(running_compiled_code=True)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 2048, in showtraceback
    value, tb, tb_offset=tb_offset)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1437, in structured_traceback
    self, etype, value, tb, tb_offset, number_of_lines_of_context)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1337, in structured_traceback
    self, etype, value, tb, tb_offset, number_of_lines_of_context
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1194, in structured_traceback
    tb_offset)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1151, in format_exception_as_a_whole
    last_unique, recursion_repeat = find_recursion(orig_etype, evalue, records)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 451, in find_recursion
    return len(records), 0
TypeError: object of type 'NoneType' has no len()

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 2045, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'TypeError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 2923, in _run_cell
    return runner(coro)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\async_helpers.py", line 68, in _pseudo_sync_runner
    coro.send(None)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 3147, in run_cell_async
    interactivity=interactivity, compiler=compiler, result=result)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 3357, in run_ast_nodes
    self.showtraceback()
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 2048, in showtraceback
    value, tb, tb_offset=tb_offset)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1437, in structured_traceback
    self, etype, value, tb, tb_offset, number_of_lines_of_context)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1337, in structured_traceback
    self, etype, value, tb, tb_offset, number_of_lines_of_context
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1212, in structured_traceback
    chained_exceptions_tb_offset)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1151, in format_exception_as_a_whole
    last_unique, recursion_repeat = find_recursion(orig_etype, evalue, records)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 451, in find_recursion
    return len(records), 0
TypeError: object of type 'NoneType' has no len()

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 2045, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'TypeError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 1170, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 316, in wrapped
    return f(*args, **kwargs)
  File "C:\Users\msi-pc\AppData\Roaming\Python\Python37\site-packages\IPython\core\ultratb.py", line 350, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 1502, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 1460, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 696, in getsourcefile
    if getattr(getmodule(object, filename), '__loader__', None) is not None:
  File "C:\Users\msi-pc\Anaconda3\lib\inspect.py", line 733, in getmodule
    if ismodule(module) and hasattr(module, '__file__'):
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Users\msi-pc\Anaconda3\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 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  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\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\__init__.py", line 42, in <module>
    from . _api.v2 import audio
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\_api\v2\audio\__init__.py", line 10, in <module>
    from tensorflow.python.ops.gen_audio_ops import decode_wav
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\python\ops\gen_audio_ops.py", line 10, in <module>
    from tensorflow.python.eager import context as _context
  File "C:\Users\msi-pc\Anaconda3\lib\site-packages\tensorflow_core\python\eager\context.py", line 25, in <module>
    from absl import logging
ModuleNotFoundError: No module named 'absl'

I'm confused why it can not run.it said internal Python error in the inspect module.it was a confusing traceback to me.我很困惑为什么它不能运行。它在检查模块中说内部 Python 错误。这对我来说是一个令人困惑的回溯。 Anyone knows what's the problem with the code or other things?有人知道代码或其他东西有什么问题吗?

In the last part of the error, we can see ModuleNotFoundError: No module named 'absl在错误的最后一部分,我们可以看到ModuleNotFoundError: No module named 'absl

You should, in theory, be able to solve that by just installing absl理论上,您应该能够通过安装absl来解决这个问题

Try installing it by running pip install absl-py尝试通过运行pip install absl-py安装它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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