【发布时间】:2021-02-09 18:09:13
【问题描述】:
我正在尝试按照以下链接中给出的步骤安装 tensorflow gpu 后导入 keras 库,
https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/
并创建了一个环境 tf-gpu。
然后我在那个环境中使用 pip install keras 安装了 keras。但是当我尝试在 jupyter notebook 中导入 keras 时,会出现以下错误,
'''
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
63 try:
---> 64 from tensorflow.python._pywrap_tensorflow_internal import *
65 # This try catch logic is because there is no bazel equivalent for py_extension.
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
~\anaconda3\lib\site-packages\keras\__init__.py in <module>
2 try:
----> 3 from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
4 except ImportError:
~\anaconda3\lib\site-packages\tensorflow\__init__.py in <module>
40
---> 41 from tensorflow.python.tools import module_util as _module_util
42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
~\anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>
39
---> 40 from tensorflow.python.eager import context
41
~\anaconda3\lib\site-packages\tensorflow\python\eager\context.py in <module>
34 from tensorflow.core.protobuf import rewriter_config_pb2
---> 35 from tensorflow.python import pywrap_tfe
36 from tensorflow.python import tf2
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tfe.py in <module>
27 # pylint: disable=invalid-import-order,g-bad-import-order, wildcard-import, unused-import
---> 28 from tensorflow.python import pywrap_tensorflow
29 from tensorflow.python._pywrap_tfe import *
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
82 above this error message when asking for help.""" % traceback.format_exc()
---> 83 raise ImportError(msg)
84
ImportError: Traceback (most recent call last):
File "C:\Users\Mayank\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
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.
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-4-88d96843a926> in <module>
----> 1 import keras
~\anaconda3\lib\site-packages\keras\__init__.py in <module>
3 from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
4 except ImportError:
----> 5 raise ImportError(
6 'Keras requires TensorFlow 2.2 or higher. '
7 'Install TensorFlow via `pip install tensorflow`')
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
'''
当我检查 tensorflow 的版本时,它显示'2.1.0'
你能帮我们解决这个问题吗?
【问题讨论】:
-
删除 TF 2.1 并安装 2.2?
-
使用
tensorflow.keras代替keras让您的生活更轻松。
标签: python python-3.x tensorflow keras