ModuleNotFoundError: No module named 'tensorflow.python.types'

ModuleNotFoundError: No module named 'tensorflow.python.types'

有谁知道如何解决这个错误?我在使用 Anaconda Navigator 时安装了 tensorflow,当我尝试在 Jupyter Notebook 上编译我的模型时出现此错误。

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-45-a28ca810f51d>", line 5, in <module>
    keras.layers.Flatten(input_shape=(39)),
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\keras\layers\core.py", line 570, in __init__
    super(Flatten, self).__init__(**kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\training\tracking\base.py", line 457, in _method_wrapper
    result = method(self, *args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 363, in __init__
    batch_input_shape = (batch_size,) + tuple(kwargs['input_shape'])
TypeError: 'int' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2040, 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:\ProgramData\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 1101, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 319, in wrapped
    return f(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 353, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "C:\ProgramData\Anaconda3\lib\inspect.py", line 1502, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
  File "C:\ProgramData\Anaconda3\lib\inspect.py", line 1460, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "C:\ProgramData\Anaconda3\lib\inspect.py", line 696, in getsourcefile
    if getattr(getmodule(object, filename), '__loader__', None) is not None:
  File "C:\ProgramData\Anaconda3\lib\inspect.py", line 733, in getmodule
    if ismodule(module) and hasattr(module, '__file__'):
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\ProgramData\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 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:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\contrib\__init__.py", line 39, in <module>
    from tensorflow.contrib import compiler
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\contrib\compiler\__init__.py", line 21, in <module>
    from tensorflow.contrib.compiler import jit
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\contrib\compiler\__init__.py", line 22, in <module>
    from tensorflow.contrib.compiler import xla
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\contrib\compiler\xla.py", line 22, in <module>
    from tensorflow.python.estimator import model_fn as model_fn_lib
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\estimator\model_fn.py", line 26, in <module>
    from tensorflow_estimator.python.estimator import model_fn
  File "C:\Users\nxf65465\AppData\Roaming\Python\Python37\site-packages\tensorflow_estimator\python\estimator\model_fn.py", line 29, in <module>
    from tensorflow.python.types import core
ModuleNotFoundError: No module named 'tensorflow.python.types'

安装的版本是:

张量流版本:2.3.1 畅达版本:4.8.3

降级到 tensorflow 2.0 对我有用。

pip install tensorflow==2.0 --user

我认为这是因为 .dll 依赖关系,但我不确定。

使用 Bazel 包生成器安装 tensorflow 后,我重新安装 tensorflow:

pip install tensorflow==2.0 --user

使用 Bazel 包生成器安装了 tensorflow,我应该重新安装 tensorflow 吗:

pip install tensorflow==2.0 --user

因为我有同样的错误:

从tensorflow.python.types导入核心 ModuleNotFoundError:没有名为 'tensorflow.python.types'

的模块

当我 运行 TF 但没有涉及 Anaconda 时...它来自 pycharm。

为了后代的利益...我遇到了与 tensorflow.python.types 相同的问题并且它不需要重新安装 tensorflow 来解决:我是 运行 TF1.15 但不知何故管理安装 tensorflow-estimator 2.4 以及

删除 TE 2.4(以及错误版本的 tensorboard)并确保我有 TF 1.15.1 并且一切都恢复正常。

顺便提一下,损坏的环境也可能是导致 cuDNN 出现奇怪的“无法加载卷积算法”错误的原因。

我不做任何具体声明,只是举出证据。

可能您使用的是 Tensorflow 版本 == 1.15,尝试在您的终端中执行下一行:

pip install tensorflow-estimator==1.15.0