简体   繁体   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). 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). I called pip install keras and that seemed to install smoothly.我打电话给pip install keras似乎安装顺利。 However calling import keras gives this error:但是调用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

So I go and install tensorflow using pip install tensorflow .所以我 go 和安装 tensorflow 使用pip install tensorflow . It seems to take a while, though eventually it installs, yet does nothing to fix my problem, and still gives me the above error.似乎需要一段时间,虽然最终它安装,但没有解决我的问题,仍然给我上述错误。 Calling import tensorflow gets me this error:调用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.

The only solutions I have found for this issue are downgrading TensorFlow and installing Visual Studio.我为这个问题找到的唯一解决方案是降级 TensorFlow 并安装 Visual Studio。 I have heard that Visual Studio is a very large program and would like to refrain from installing it.我听说 Visual Studio 是一个非常大的程序,我不想安装它。 As for downgrading TensorFlow, I feel there should be a better solution.至于降级TensorFlow,感觉应该有更好的解决方案。 What is it about Visual Studio that makes TensorFlow work, and is there a way I can get that(Certain DLLs or dependencies) without having to get everything else along with Visual Studio?使 TensorFlow 工作的 Visual Studio 是什么,有没有办法我可以得到它(某些 DLL 或依赖项),而无需使用 Visual Studio 获取其他所有内容? These are links to places I have seen this:这些是我看到的地方的链接:

  1. Tensorflow on windows - ImportError: DLL load failed: The specified module could not be found windows 上的 Tensorflow - ImportError: DLL 加载失败:找不到指定的模块

2. https://github.com/tensorflow/tensorflow/issues/35749 2. https://github.com/tensorflow/tensorflow/issues/35749

3. https://medium.com/@mdiqbalbajmi00786/importerror-keras-requires-tensorflow-2-2-e9f128c5fbf6 3. https://medium.com/@mdiqbalbajmi00786/importerror-keras-requires-tensorflow-2-2-e9f128c5fbf6

According to tensorflow installation , you should have pre installed C++ redistributable for windows 7 or later.根据tensorflow 安装,您应该已经预先安装了C++ 可再分发windows 7 或更高版本。

Also you can directly download the tensorflow wheel from here just make sure to choose correct operating system, architecture and python version while downloading.您也可以直接从这里下载 tensorflow 轮,下载时请确保选择正确的操作系统、架构和 python 版本。 Then you can do然后你可以做

pip install path_t_wheel_file.whl

I have heard that Visual Studio is a very large program and would like to refrain from installing it.我听说 Visual Studio 是一个非常大的程序,我不想安装它。

You do not have to install entire visual studio just the C++ redistributable您不必安装整个 Visual Studio,只需C++ 可再发行组件

What is it about Visual Studio that makes TensorFlow work,使 TensorFlow 工作的 Visual Studio 是什么,

I haven't looked into tensorflow's source code but I think It is written in C++ so it requires additional libs that are provided by the c++ redistributables我没有查看 tensorflow 的源代码,但我认为它是用C++编写的,因此它需要 c++ 可再发行组件提供的其他库

This may help这可能会有所帮助
create new environment don't install packages in base environment (optional but it fixed tensorflow installation bugs for me)创建新环境不要在基础环境中安装软件包(可选,但它为我修复了 tensorflow 安装错误)

conda install -c conda-forge tensorflow to install tensorflow conda install -c conda-forge tensorflow安装 tensorflow
then pip install keras or conda install -c conda-forge keras然后pip install keras或 conda conda install -c conda-forge keras

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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