【问题标题】:ERROR:root:Internal Python error in the inspect module while installing Tensorflow错误:root:安装 Tensorflow 时检查模块中的内部 Python 错误
【发布时间】:2020-05-25 06:29:39
【问题描述】:

我已经安装了带有 CUDA 10.1、cuDNN SDK = 7.6 的 TensorFlow 2.0 以及所有不同的库,例如 pandas、sci-kit learn、Keras、NumPy、Gensim 等。这个错误可能是由于新的 TensorFlow 版本。当我尝试通过运行此确认代码来确认它时。我收到一个错误。请帮忙。

import sys

import tensorflow.keras
import pandas as pd
import sklearn as sk
import tensorflow as tf

print(f"Tensor Flow Version: {tf.__version__}")
print(f"Keras Version: {tensorflow.keras.__version__}")
print()
print(f"Python {sys.version}")
print(f"Pandas {pd.__version__}")
print(f"Scikit-Learn {sk.__version__}")
print("GPU is", "available" if tf.test.is_gpu_available() else "NOT AVAILABLE")

我遇到的错误:

WARNING:tensorflow:From C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\ops\distributions\distribution.py:265: ReparameterizationType.__init__ (from tensorflow.python.ops.distributions.distribution) is deprecated and will be removed after 2019-01-01.
Instructions for updating:
The TensorFlow Distributions library has moved to TensorFlow Probability (https://github.com/tensorflow/probability). You should update all references to use `tfp.distributions` instead of `tf.distributions`.
WARNING:tensorflow:From C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\ops\distributions\bernoulli.py:169: RegisterKL.__init__ (from tensorflow.python.ops.distributions.kullback_leibler) is deprecated and will be removed after 2019-01-01.
Instructions for updating:
The TensorFlow Distributions library has moved to TensorFlow Probability (https://github.com/tensorflow/probability). You should update all references to use `tfp.distributions` instead of `tf.distributions`.
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.

Traceback (most recent call last):
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-0b3eb45acbe5>", line 3, in <module>
    import tensorflow.keras
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
    from tensorflow_core import *
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2044, 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 "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\IPython\core\ultratb.py", line 1151, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\IPython\core\ultratb.py", line 319, in wrapped
    return f(*args, **kwargs)
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\IPython\core\ultratb.py", line 353, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\inspect.py", line 1502, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\inspect.py", line 1460, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\inspect.py", line 696, in getsourcefile
    if getattr(getmodule(object, filename), '__loader__', None) is not None:
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\inspect.py", line 733, in getmodule
    if ismodule(module) and hasattr(module, '__file__'):
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Users\Abdul\.conda\envs\tensorflow\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\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\__init__.py", line 45, in <module>
    from . _api.v2 import compat
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\_api\v2\compat\__init__.py", line 23, in <module>
    from . import v1
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\_api\v2\compat\v1\__init__.py", line 40, in <module>
    from . import experimental
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\_api\v2\compat\v1\experimental\__init__.py", line 11, in <module>
    from tensorflow.python.ops.control_flow_v2_toggles import output_all_intermediates
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\ops\control_flow_v2_toggles.py", line 24, in <module>
    from tensorflow.python.ops import control_flow_util_v2
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\ops\control_flow_util_v2.py", line 28, in <module>
    from tensorflow.python.keras.engine import base_layer_utils
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\__init__.py", line 27, in <module>
    from tensorflow.python.keras import applications
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\applications\__init__.py", line 25, in <module>
    from tensorflow.python.keras import engine
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\__init__.py", line 23, in <module>
    from tensorflow.python.keras.engine.base_layer import Layer
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 56, in <module>
    from tensorflow.python.keras.saving.saved_model import layer_serialization
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\saving\__init__.py", line 20, in <module>
    from tensorflow.python.keras.saving.hdf5_format import load_attributes_from_hdf5_group
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 32, in <module>
    from tensorflow.python.keras.utils import conv_utils
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\utils\__init__.py", line 38, in <module>
    from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\utils\multi_gpu_utils.py", line 22, in <module>
    from tensorflow.python.keras.engine.training import Model
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 42, in <module>
    from tensorflow.python.keras import metrics as metrics_module
  File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\metrics.py", line 34, in <module>
    from tensorflow.python.keras.engine.base_layer import Layer
ImportError: cannot import name 'Layer' from 'tensorflow.python.keras.engine.base_layer' (C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py)
---------------------------------------------------------------------------

​

【问题讨论】:

  • 你能说明你是如何安装这些库的吗?
  • 使用 pip 安装库名称。我已经安装了 sklearn、pandas、pandas-datareader、matplotlib、spacy、gensim、spacy
  • 你没有使用 Conda 吗?
  • 不,我使用 pip 安装不同的库
  • 我的意思是你不是在虚拟环境中使用 Conda 吗?

标签: python tensorflow installation anaconda


【解决方案1】:

我在 Windows 10 虚拟机上遇到了同样的错误。由于您使用的是 Anaconda,请尝试:

pip uninstall tensorflow

那就试试conda install tensorflow

然后尝试通过以下方式导入您的 Keras 包:from tensorflow.keras.xxx import xxx

如上面的 cmets 所述,可能值得尝试在 conda 中设置一个虚拟环境,并在那里安装所需的包。

【讨论】:

    【解决方案2】:

    在 Anaconda 中,您看不到 pip 卸载提示您“是否要继续 (Y/N)?因此您应该添加 --yes: pip uninstall tensorflow --yes

    【讨论】:

      【解决方案3】:

      我通过下载和安装解决了这个问题 “适用于 Visual Studio 2015、2017 和 2019 的 Microsoft Visual C++ Redistributable”。它对我有用。

      先决条件:Python + Jupyter notebook + tensorflow 安装已经完成

      “导入 tensorflow”时出现此错误

      按照以下步骤操作:

      第 1 步:下载“Microsoft Visual C++ Redistributable for Visual Studio 2015、2017 和 2019 - 社区版”

      第 2 步:在安装 Microsoft Visual C++ Redistributable for Visual Studio 2015、2017 和 2019 时选择“Python 工作负载”

      第 3 步:重新启动计算机一次

      第4步:就是这样,现在打开Jupyter notebook和“import tensorflow”就不会出现错误了

      【讨论】:

        【解决方案4】:

        如果您在 Google colab 上收到此错误,请将运行时重置为出厂设置。点击运行时,然后恢复出厂设置运行时

        【讨论】:

        • 同样适用于任何 jupyter 内核。金 - 谢谢!
        【解决方案5】:

        如果发生在Google Colab:
        在顶部菜单中点击Runtime > Restart Runtime

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-03-12
          • 1970-01-01
          • 2013-08-12
          • 2022-01-11
          • 1970-01-01
          • 2016-06-11
          相关资源
          最近更新 更多