【问题标题】:Python 3.8.1: ModuleNotFoundError: No module named '_pywrap_tensorflow_internal' - Is tensorflow only supported up to 3.7?Python 3.8.1:ModuleNotFoundError:没有名为“_pywrap_tensorflow_internal”的模块 - tensorflow 是否仅支持到 3.7?
【发布时间】:2020-01-26 16:41:29
【问题描述】:

我在 Windows 10 上使用 Python 3.8.1 并尝试安装 TensorFlow。

我尝试了很多方法来安装它,但是在导入 TensorFlow 时我不断收到以下错误。这一次,我使用安装它

conda install -c conda-forge tensorflow

这是堆栈跟踪:

Using TensorFlow backend.
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
  File "C:\Program Files (x86)\Python38-32\lib\imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    import _pywrap_tensorflow_internal
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "deep_versions.py", line 6, in <module>
    import keras
  File "C:\Users\rapto\AppData\Roaming\Python\Python38\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils
  File "C:\Users\rapto\AppData\Roaming\Python\Python38\site-packages\keras\utils\__init__.py", line 6, in <module>
    from . import conv_utils
  File "C:\Users\rapto\AppData\Roaming\Python\Python38\site-packages\keras\utils\conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "C:\Users\rapto\AppData\Roaming\Python\Python38\site-packages\keras\backend\__init__.py", line 1, in <module>
    from .load_backend import epsilon
  File "C:\Users\rapto\AppData\Roaming\Python\Python38\site-packages\keras\backend\load_backend.py", line 90, in <module>
    from .tensorflow_backend import *
  File "C:\Users\rapto\AppData\Roaming\Python\Python38\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
  File "C:\Program Files (x86)\Python38-32\lib\imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    import _pywrap_tensorflow_internal
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

我为修复它所做的工作:我在这里查看了其他类似的问题,但它们是针对旧版本的 Python 的。我还查看了this GitHub post,但无法解决问题。

我查看了 TensorFlow 网站的 Python 版本兼容性,但我能找到的最新更新是几个月前,说 TensorFlow 仅支持最高 Python 3.7(https://github.com/tensorflow/tensorflow/issues/33374) 仍然是这种情况,我需要降级吗? Python 为了使用 TensorFlow?

如果我应该提供更多信息,请告诉我(我仍在学习如何在这里正确提问)。谢谢。

编辑:我使用 Python 3.7 创建了一个 conda 环境,但没有遇到同样的错误,现在导入 TF 似乎工作正常。看来 Python 3.8 还不支持,所以这可能是问题所在。

【问题讨论】:

  • 我使用 conda 和 Python 3.7 创建了一个环境,并且安装 TF 工作正常。我仍然无法从 TF 网站确定是否支持 Python 3.8,但如果不支持,那可能与我收到此 ModuleNotFoundError 的原因有关。我希望这个对我自己问题的回答可以帮助任何可能遇到同样问题的人。

标签: python-3.x tensorflow anaconda conda


【解决方案1】:

根据安装文档,仅支持 Python 3.5-3.7。 https://www.tensorflow.org/install

【讨论】:

    【解决方案2】:

    我认为这与 python 或 TensorFlow 的版本有关,您应该更改 Python 或 TensorFlow 的版本,因为您使用的这两个版本不兼容。您可以降级到 Python3.6 或尝试支持 Python 3.7 的 Tensorflow>=1.13.1。它应该可以正常工作。

    【讨论】:

      【解决方案3】:

      对我来说,我设法通过使用 conda create -n &lt;venv name&gt; python=3.6 创建一个 venv 来修复它。需要注意的是,指定的 python 版本需要是 3.6。然后,使用相同的命令,不同之处在于我使用了tensor-gpu 而不是conda install -c conda-forge tensorflow-gpu。请注意,我机器上的 python 版本是 3.7.8,但我想 3.5-3.8 的任何版本都应该没问题。希望它在未来仍然对某人有所帮助!

      【讨论】:

        猜你喜欢
        • 2020-08-04
        • 1970-01-01
        • 2020-12-21
        • 2020-08-23
        • 1970-01-01
        • 1970-01-01
        • 2018-12-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多