Tensorflow 2.1.0 - DLL 加载失败 - windows cpu

Posted

技术标签:

【中文标题】Tensorflow 2.1.0 - DLL 加载失败 - windows cpu【英文标题】:Tensorflow 2.1.0 - DLL load failed - windows cpu 【发布时间】:2020-06-02 07:12:07 【问题描述】:

TensorFlow 2.1.0 安装成功,但 TensorFlow 导入失败。

开放式问题:

是否存在无法加载的位于不同位置/未安装在系统上的库?

复制程序:

1) 创造环境

conda create --name tensorflow21_env

2) 激活环境

conda activate tensorflow21_env

3) 安装

    conda install python=3.7 pip install tensorflow-cpu #install tensorflow=2.1.0;

4) 测试

python -c "import tensorflow as tf"

堆栈跟踪:

    Traceback (most recent call last):
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "C:\Anaconda3\envs\tensorflow21_env\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Anaconda3\envs\tensorflow21_env\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
    from tensorflow_core import *
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Anaconda3\envs\tensorflow21_env\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "C:\Anaconda3\envs\tensorflow21_env\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Anaconda3\envs\tensorflow21_env\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.


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.

安装输出:

输出:conda install python=3.7

Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Anaconda3\envs\tensorflow21_env

  added / updated specs:
    - python=3.7


The following NEW packages will be INSTALLED:

  ca-certificates    pkgs/main/win-64::ca-certificates-2020.1.1-0
  certifi            pkgs/main/win-64::certifi-2019.11.28-py37_0
  openssl            pkgs/main/win-64::openssl-1.1.1d-he774522_4
  pip                pkgs/main/win-64::pip-20.0.2-py37_1
  python             pkgs/main/win-64::python-3.7.6-h60c2a47_2
  setuptools         pkgs/main/win-64::setuptools-45.2.0-py37_0
  sqlite             pkgs/main/win-64::sqlite-3.31.1-he774522_0
  vc                 pkgs/main/win-64::vc-14.1-h0510ff6_4
  vs2015_runtime     pkgs/main/win-64::vs2015_runtime-14.16.27012-hf0eaf9b_1
  wheel              pkgs/main/win-64::wheel-0.34.2-py37_0
  wincertstore       pkgs/main/win-64::wincertstore-0.2-py37_0


Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done

依赖遍历器确认所有 DLL 都可以加载 (download dependency walker)。

dependency_trace

插件: 依赖walker的路径

C:\Anaconda3\envs\tensorflow21_env\Lib\site-packages\tensorflow_core\python\_pywrap_tensorflow_internal.pyd

更新:

我的处理器既不支持 AVX 也不支持 AVX2,因此无法安装 tensorflow pip 包,或者更准确地说,无法导入 tensorflow 包。

临时解决方案:

不支持 AVX 的旧版和低端 CPU 的临时解决方案是为 tensorflow 安装 SSE-prebuild-binaries。 转到 tensorflow-windows-wheel 并按照说明安装 tensorflow 2.0.0 或 2.1.0。

【问题讨论】:

【参考方案1】:

试试这个方法: 卸载您使用 pip 安装的 TensorFlow 包,然后使用 conda install tensorflow 重新安装,这可能有效!现在您可以毫无问题地导入 TensorFlow。我希望这可以帮助你。

如果您需要更详细的步骤。在这里,您可以执行以下操作。

以管理员身份运行 anaconda 提示符。 (右键->以管理员身份运行)。

pip uninstall tensorflow

关闭 anaconda 提示符。

再次以管理员身份运行 anaconda 提示符。

类型: conda install tensorflow 它会要求一些y / n 输入y

现在完成后,将 python 解释器的环境更改为安装 tensorflow 的 anaconda 环境。

现在尝试导入 tensorflow。

我希望这会有所帮助。

【讨论】:

有人试过这个答案吗?我不想卸载 tensorflow 2.0,因为我很难安装它? 我试过 conda install tensorflow 作为卸载它。 (1) 我没有收到 TF 安装成功的消息 (2) 当我导入 tensorflow 时出现错误 ImportError: DLL load failed: The specified module could not be found.我真的很挣扎,因为我认为这里的说明会帮助我medium.com/analytics-vidhya/…

以上是关于Tensorflow 2.1.0 - DLL 加载失败 - windows cpu的主要内容,如果未能解决你的问题,请参考以下文章

tensorflow:无法加载动态库“cudart64_110.dll”; dlerror: 未找到 cudart64_110.dll

TensorFlow ImportError:导入_pywrap_tensorflow_internal时DLL加载失败:找不到指定的模块

windows server 2016 中导入 tensorflow 错误(DLL 加载失败导入 _pywrap_tensorflow_internal)

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

导入具有GPU支持的TensorFlow时DLL加载失败

Tensorflow GPU 无法加载动态库“cusolver64_10.dll”; dlerror: 未找到 cusolver64_10.dll