简体   繁体   English

ModuleNotFoundError:没有名为“tensorflow.python.types”的模块

[英]ModuleNotFoundError: No module named 'tensorflow.python.types'

Does anyone know how to solve this error?有谁知道如何解决这个错误? I have tensorflow installed as I am using Anaconda Navigator and I get this error when trying to compile my model on Jupyter Notebook.我在使用 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'

The installed versions are:安装的版本是:

Tensorflow Version: 2.3.1 conda version: 4.8.3 Tensorflow 版本:2.3.1 conda 版本:4.8.3

Downgrading to tensorflow 2.0 worked for me.降级到 tensorflow 2.0 对我有用。

pip install tensorflow==2.0 --user

I think it is because of .dll dependencies but I am not sure.我认为这是因为 .dll 依赖关系,但我不确定。

使用 Bazel 包构建器安装了 tensorflow 后,我使用以下命令重新安装了 tensorflow:

pip install tensorflow==2.0 --user

Having installed tensorflow with Bazel package builder, shall I reinstall tensor flow with:使用 Bazel 包构建器安装了 tensorflow 后,我应该使用以下命令重新安装 tensor flow:

pip install tensorflow==2.0 --user pip install tensorflow==2.0 --user

Because I have the same error:因为我有同样的错误:

from tensorflow.python.types import core ModuleNotFoundError: No module named 'tensorflow.python.types' from tensorflow.python.types import core ModuleNotFoundError: No module named 'tensorflow.python.types'

When I run TF but no Anaconda involved... It is from pycharm.当我运行 TF 但没有涉及 Anaconda 时......它来自 pycharm。

For the benefit of posterity... I had the same problem with tensorflow.python.types and it did not require a resintallation of tensorflow to resolve: I was running TF1.15 but had somehow managed to get tensorflow-estimator 2.4 installed as well .为子孙后代造福。我曾与tensorflow.python.types同样的问题,它并不需要tensorflow来解决resintallation:我是跑TF1.15但不知何故设法tensorflow,估计2.4安装好了.

Removing TE 2.4 (and the wrong version of tensorboard) and making sure I had TF 1.15.1 and all was well again.删除 TE 2.4(和错误版本的 tensorboard)并确保我有 TF 1.15.1 并且一切正常。

To note in passing, the mangled environment might also have been responsible for the strange "cannot load the convolution algorithm" error with cuDNN.顺便提一下,损坏的环境也可能是 cuDNN 出现奇怪的“无法加载卷积算法”错误的原因。

I make no specific claims, merely adduce evidence.我不做具体的主张,只是举出证据。

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

pip install tensorflow-estimator==1.15.0

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

相关问题 ModuleNotFoundError:没有名为“tensorflow.python.training”的模块 - ModuleNotFoundError: No module named 'tensorflow.python.training' Python-TensorFlow-ModuleNotFoundError:没有名为x的模块 - Python - TensorFlow - ModuleNotFoundError: No module named x FLASK PYTHON ModuleNotFoundError:没有名为“tensorflow”的模块 - FLASK PYTHON ModuleNotFoundError: No module named 'tensorflow' ModuleNotFoundError:没有名为“tensorflow”的模块? - ModuleNotFoundError: No module named 'tensorflow'? ModuleNotFoundError:没有名为“tensorflow.python.util”的模块 - ModuleNotFoundError: No module named 'tensorflow.python.util' ModuleNotFoundError:没有名为“tensorflow.python.trackable”的模块 - ModuleNotFoundError: No module named 'tensorflow.python.trackable' ModuleNotFoundError:没有名为“tensorflow.python”的模块 Anaconda - ModuleNotFoundError: No module named 'tensorflow.python' Anaconda ModuleNotFoundError:在蟒蛇python 3.6.3中没有名为&#39;tensorflow&#39;的模块 - ModuleNotFoundError: No module named ‘tensorflow’ in anaconda python 3.6.3 ModuleNotFoundError:没有名为“tensorflow.python.checkpoint”的模块 - ModuleNotFoundError: No module named 'tensorflow.python.checkpoint' ModuleNotFoundError:没有名为“tensorflow”的模块 - ModuleNotFoundError: No module named 'tensorflow'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM