繁体   English   中英

在 Anaconda ZA7F5F35426B927411FC9231B5638217Z 中安装 Keras 和 TensorFlow 时遇到问题

[英]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 获取其他所有内容? 这些是我看到的地方的链接:

  1. windows 上的 Tensorflow - ImportError: DLL 加载失败:找不到指定的模块

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM