[英]Trouble Installing Keras and TensorFlow in Anaconda Python
I am trying to use Keras in Anaconda Python on my 64 bit Windows 10 computer that does not have a GPU(I don't know if that is significant or not). 我打電話給pip install keras
似乎安裝順利。 但是調用import keras
會出現此錯誤:
Traceback (most recent call last):
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\jsmith\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\jsmith\anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\jsmith\anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\jsmith\anaconda3\lib\site-packages\keras\__init__.py", line 3, in <module>
from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\jsmith\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\jsmith\anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\jsmith\anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: 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:
Traceback (most recent call last):
File "C:\Users\jsmith\Desktop\Code\JohnWorkspaces\Machine_Learning\BeginningWithPydev\main\main.py", line 1, in <module>
import keras
File "C:\Users\jsmith\anaconda3\lib\site-packages\keras\__init__.py", line 6, in <module>
'Keras requires TensorFlow 2.2 or higher. '
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via pip install tensorflow
所以我 go 和安裝 tensorflow 使用pip install tensorflow
. 似乎需要一段時間,雖然最終它安裝,但沒有解決我的問題,仍然給我上述錯誤。 調用import tensorflow
給我這個錯誤:
Traceback (most recent call last):
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\jsmith\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\jsmith\anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\jsmith\anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\jsmith\Desktop\Code\JohnWorkspaces\Machine_Learning\BeginningWithPydev\main\main.py", line 1, in <module>
import tensorflow
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\jsmith\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\jsmith\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\jsmith\anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\jsmith\anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: 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.
我為這個問題找到的唯一解決方案是降級 TensorFlow 並安裝 Visual Studio。 我聽說 Visual Studio 是一個非常大的程序,我不想安裝它。 至於降級TensorFlow,感覺應該有更好的解決方案。 使 TensorFlow 工作的 Visual Studio 是什么,有沒有辦法我可以得到它(某些 DLL 或依賴項),而無需使用 Visual Studio 獲取其他所有內容? 這些是我看到的地方的鏈接:
2. https://github.com/tensorflow/tensorflow/issues/35749
3. https://medium.com/@mdiqbalbajmi00786/importerror-keras-requires-tensorflow-2-2-e9f128c5fbf6
根據tensorflow 安裝,您應該已經預先安裝了C++ 可再分發windows 7 或更高版本。
您也可以直接從這里下載 tensorflow 輪,下載時請確保選擇正確的操作系統、架構和 python 版本。 然后你可以做
pip install path_t_wheel_file.whl
我聽說 Visual Studio 是一個非常大的程序,我不想安裝它。
您不必安裝整個 Visual Studio,只需C++ 可再發行組件
使 TensorFlow 工作的 Visual Studio 是什么,
我沒有查看 tensorflow 的源代碼,但我認為它是用C++
編寫的,因此它需要 c++ 可再發行組件提供的其他庫
這可能會有所幫助
創建新環境不要在基礎環境中安裝軟件包(可選,但它為我修復了 tensorflow 安裝錯誤)
conda install -c conda-forge tensorflow
安裝 tensorflow
然后pip install keras
或 conda conda install -c conda-forge keras
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.