首页 > 解决方案 > 无法导入 TensorFlow 和 Keras

问题描述

我无法导入 TensorFlow 和 Keras。我已经成功安装了它们并且能够看到版本,但是在导入时出现以下错误。

ImportError: DLL load failed: The specified procedure could not be found.

Product Versions

Python Version - 3.6
---
Anaconda Version - 4.3.1
--
Keras Version - 2.2.4
--------------------
TensorFlow Version - 1.31.1
-------------------------------

ImportError: DLL load failed: The specified procedure could not be found.

ImportError                               Traceback (most recent call last)
<ipython-input-1-41389fad42b5> in <module>()
1 import tensorflow as tf

C:\Users\kolasay\AppData\Roaming\Python\Python36\site-packages\tensorflow\__init__.py in <module>()
     22 
     23 # pylint: disable=g-bad-import-order
    24 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
     25 
     26 from tensorflow._api.v1 import app

C:\Users\kolasay\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\__init__.py in <module>()
     50 
     51 # Protocol buffers
     52 from tensorflow.core.framework.graph_pb2 import *
     53 from tensorflow.core.framework.node_def_pb2 import *
     54 from tensorflow.core.framework.summary_pb2 import *

C:\Users\kolasay\AppData\Roaming\Python\Python36\site-packages\tensorflow\core\framework\graph_pb2.py in <module>()
      4 import sys
      5 _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
     6 from google.protobuf import descriptor as _descriptor
      7 from google.protobuf import message as _message
      8 from google.protobuf import reflection as _reflection

C:\Users\kolasay\AppData\Roaming\Python\Python36\site-packages\google\protobuf\descriptor.py in <module>()
     45   import binascii
     46   import os
    47   from google.protobuf.pyext import _message
     48   _USE_C_DESCRIPTORS = getattr(_message, '_USE_C_DESCRIPTORS', False)
     49 

ImportError: DLL load failed: The specified procedure could not be found.

标签: pythontensorflowkeras

解决方案


通过这个线程,我可以建议以下内容

https://github.com/protocolbuffers/protobuf/issues/5046

  1. 将 Protobuf 降级到稳定版本
  2. 将 Python 升级到 3.6.1

将来我可能会建议为玩具项目选择像 Google Colab 这样的在线环境,因为它设置起来不那么麻烦。


推荐阅读