【问题标题】:Tensorflow error "No module named 'tensorflow_core.estimator'"TensorFlow 错误“没有名为 'tensorflow_core.estimator' 的模块”
【发布时间】:2022-03-08 23:39:48
【问题描述】:

我使用以下 .yml 文件在 conda 中构建了一个新环境:

名称:py37 频道:

  • conda-forge
  • 默认依赖项:
  • python=3.7.7
  • cartopy=0.18.0
  • earthengine-api=0.1.221
  • flake8=3.8.1
  • jupyterlab=2.1.2
  • jupyter_contrib_nbextensions=0.5.1
  • matplotlib=3.2.1
  • mypy=0.770
  • nb_conda=2.2.1 # 可选,对于在 Jupyter 笔记本中运行 R 很有用
  • numpy=1.18.4
  • 熊猫=1.0.3
  • 枕头=7.1.2
  • scikit-learn=0.23.0
  • scipy=1.4.1
  • seaborn=0.10.1
  • tqdm=4.46.0
  • tensorflow=1.15.0 # 最高只支持 Python 3.7

我现在在 .ipynb 文件中运行以下部分

from pprint import pprint import os import sys

import matplotlib.pyplot as plt import numpy as np import pandas as pd import tensorflow as tf

sys.path.append('../') from preprocessing.helper import get_first_feature_map, get_feature_types from utils.geo_plot import setup_ax

我不断收到以下错误:

Error in callback <bound method AutoreloadMagics.post_execute_hook of <autoreload.AutoreloadMagics object at 0x7fba286b3a50>> (for post_execute): Traceback (most recent call last):   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/IPython/core/events.py", line 89, in trigger
    func(*args, **kwargs)   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/IPython/extensions/autoreload.py", line 538, in post_execute_hook
    _, pymtime = self._reloader.filename_and_mtime(sys.modules[modname])   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/IPython/extensions/autoreload.py", line 184, in filename_and_mtime
    if not hasattr(module, '__file__') or module.__file__ is None:   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/tensorflow/__init__.py", line 50, in __getattr__
    module = self._load()   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/tensorflow/__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/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 "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/contrib/__init__.py", line 39, in <module>
    from tensorflow.contrib import compiler   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/contrib/compiler/__init__.py", line 21, in <module>
    from tensorflow.contrib.compiler import jit   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/contrib/compiler/__init__.py", line 22, in <module>
    from tensorflow.contrib.compiler import xla   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/contrib/compiler/xla.py", line 22, in <module>
    from tensorflow.python.estimator import model_fn as model_fn_lib   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/tensorflow_core/python/estimator/model_fn.py", line 26, in <module>
    from tensorflow_estimator.python.estimator import model_fn   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/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'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2077, in showtraceback
    stb = value._render_traceback_() AttributeError: 'ModuleNotFoundError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/IPython/core/ultratb.py", line 1101, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/IPython/core/ultratb.py", line 248, in wrapped
    return f(*args, **kwargs)   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/IPython/core/ultratb.py", line 281, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/inspect.py", line 1502, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/inspect.py", line 1460, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/inspect.py", line 696, in getsourcefile
    if getattr(getmodule(object, filename), '__loader__', None) is not None:   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/inspect.py", line 733, in getmodule
    if ismodule(module) and hasattr(module, '__file__'):   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/tensorflow/__init__.py", line 50, in __getattr__
    module = self._load()   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/site-packages/tensorflow/__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)   File "/Users/prernamishra/opt/miniconda3/envs/py37/lib/python3.7/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 965, in _find_and_load_unlocked ModuleNotFoundError: No module named 'tensorflow_core.estimator'

我还需要安装其他东西吗?原始的 yml 文件有 - tensorflow==1.15.0 但我更改了它,因为我在 Mac 上运行它并且它不起作用。

感谢任何帮助!

【问题讨论】:

    标签: python python-3.x tensorflow


    【解决方案1】:

    能否请您升级到 tensorflow 2.c [2.7] 并确保 python 和操作系统为 64 位。 你也可以试试:

    pip install --upgrade pip
    pip uninstall tensorflow
    pip install tensorflow
    

    如果错误仍然存​​在:

    创建虚拟环境

    cd <your project path>
    
    Install virtualenv
    
    pip install virtualenv
    

    创建虚拟环境

    virtualenv &lt;envname>

    激活环境

    Windows Powershell:.\Scripts\activate 带有 Bash 或 zsh 的 Unix:source /bin/activate 然后现在你安装 tensorflow

    (<envname>) $ pip install tensorflow
    

    然后成功运行Hello World。

    *别忘了每次虚拟环境jupyter、命令行等都需要激活或配置。

    【讨论】:

      猜你喜欢
      • 2021-05-07
      • 2018-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多