請教import keras 之錯誤訊息問題
您好:
我已安裝Keras(2.4.3),及tensorflow(2.2.0),
請問,為什麼執行D66 程式,還會出現以下錯誤訊息
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
請問, 跟版本問題有關嗎? 應該如何解決?謝謝.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
57
---> 58 from tensorflow.python.pywrap_tensorflow_internal import *
59
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in <module>
27 return _mod
---> 28 _pywrap_tensorflow_internal = swig_import_helper()
29 del swig_import_helper
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()
23 try:
---> 24 _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
25 finally:
~\anaconda3\lib\imp.py in load_module(name, file, filename, details)
241 else:
--> 242 return load_dynamic(name, filename, file)
243 elif type_ == PKG_DIRECTORY:
~\anaconda3\lib\imp.py in load_dynamic(name, path, file)
341 name=name, loader=loader, origin=path)
--> 342 return _load(spec)
343
ImportError: DLL load failed with error code 3221225501
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>
49
---> 50 from tensorflow.python import pywrap_tensorflow
51
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
68 above this error message when asking for help.""" % traceback.format_exc()
---> 69 raise ImportError(msg)
70
ImportError: Traceback (most recent call last):
File "C:\Users\UserA\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\UserA\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\UserA\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\UserA\anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\UserA\anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed with error code 3221225501
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-16-cd05093a7a19> in <module>
1 # 載入套件
----> 2 import keras
3 from keras import backend as K
4 from keras.layers import Layer
~\anaconda3\lib\site-packages\keras\__init__.py in <module>
4 except ImportError:
5 raise ImportError(
----> 6 'Keras requires TensorFlow 2.2 or higher. '
7 'Install TensorFlow via `pip install tensorflow`')
8
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
============================================================================
回答列表
-
2020/06/30 下午 09:58Jeffrey贊同數:0不贊同數:0留言數:6
請問一下, 是先安裝 Keras 還是 先安裝tensorflow?
嘗試 tensorflow 後裝
-
2020/07/01 上午 00:56張維元 (WeiYuan)贊同數:0不贊同數:0留言數:2
這邊表示版本對不上,可以把 tensorflow 先移除,重新安裝指定的版本。
如果這個回答對你有幫助請主動點選「有幫助」的按鈕,也可以追蹤我的GITHUB帳號。若還有問題的話,也歡迎繼續再追問或者把你理解的部分整理上來,我都會提供你 Review 和 Feedback 😃😃😃
-
2020/07/02 下午 02:16張維元 (WeiYuan)贊同數:1不贊同數:0留言數:1
「已找到原因了,要先建立tensorflow 虛擬環境才可以安裝keras 建議修改講義,把安裝tensorflow & keras 的流程 講更清楚」
=> 我可以幫你回報給主辦單位:)