【发布时间】: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