![](/img/trans.png)
[英]ImportError: DLL load failed: The specified module could not be found when importing keras
[英]How to fix - ImportError: DLL load failed, when importing keras
我正在嘗試使用 tensorflow 后端安裝 keras
我首先運行pip install keras
,然后pip install tensorflow
兩個命令都成功完成,現在當我嘗試從 keras.models 導入 Sequential 時出現錯誤
這是我的代碼
這是錯誤
Using TensorFlow backend.
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\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\Admin\AppData\Local\Programs\Python\Python36\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: Произошел сбой в программе инициализации библиотеки динамической компоновки (DLL).
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Admin/PycharmProjects/keras/test.py", line 3, in <module>
from keras.models import Sequential
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
from . import conv_utils
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
from .. import backend as K
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
from .tensorflow_backend import *
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
import tensorflow as tf
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\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\Admin\AppData\Local\Programs\Python\Python36\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: Произошел сбой в программе инициализации библиотеки динамической компоновки (DLL).
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.
我不知道為什么錯誤是俄語,也許是因為我的系統語言,但這里是翻譯
Original error:
ImportError: DLL load failed: Произошел сбой в программе инициализации библиотеки динамической компоновки (DLL)
Translation:
ImportError: DLL load failed: A crash occurred in the dynamic link library initialization program. (DLL)
我在用
和 Python 3.6.0
有人可以幫我解決這個問題嗎?
方法一
因此,根據您提供的信息,請按照以下步驟操作:
現在,我們需要安裝這個文件。 用,
pip install tensorflow-1.12.0-cp36-cp36m-win_amd64.whl
如果顯示任何錯誤,請嘗試將相對路徑更改為絕對路徑。
TensorFlow 安裝成功。
方法二
安裝蟒蛇。 它使用一個名為conda
的包管理器,類似於pip
。
創建一個新的 Conda 環境。
conda create --name mytfenv
安裝 TensorFlow(版本=1.10.0)
conda install tensorflow
其中一種方法對您有用。 我個人采用了這兩種方法,因為我的 CPU 規格與您的規格相匹配。
Tensorflow 1.12 與tf.keras
( tf.keras
: https://www.tensorflow.org/guide/keras ) 一起發布。 所以你必須先導入tensorflow和keras,然后使用keras.Sequential
來創建層。
import tensorflow as tf
from tensorflow import keras
#for example
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(128, activation=tf.nn.relu),
keras.layers.Dense(10, activation=tf.nn.softmax)
])
更多信息請參考官方教程:https ://www.tensorflow.org/tutorials/keras/basic_classification
對於 CPU,您可以通過在 jupyter notebook 中運行以下 python 代碼來簡單地安裝 tensorflow。 我希望你安裝了anaconda!
pip.main(['install','tensorflow==1.5'])
版本大於 1.6 的 tensorflow 可能會給您帶來問題,但它帶有一些有用的功能
我在 Windows 10 上使用 Python 3.7、Jypyter Notebook 時遇到同樣的問題。然后執行以下操作:
並在我的 Jypyter Notebook 中的tensorflow 網站上執行安裝指南:
pip install --upgrade pip
pip install tensorflow
import tensorflow
或import keras
正常工作。您可以安裝 Anaconda,創建虛擬環境,在其上安裝 Keras 和 Tensorflow,如果仍然在 jupyter notebook 中出現 DLL 導入錯誤 - https://support.microsoft.com/en-us/help/2977003/the-latest-supported- visual-c-downloads打開鏈接,下載 x64 .exe 文件並安裝它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.