“无法加载本机TensorFlow运行时。”

时间:2019-11-13 03:27:02

标签: python python-3.x tensorflow

所以我创建了一个程序来从TensorFlow加载数据集,但出现一个错误,我不知道它是什么意思。

我的代码是:

import tensorflow as tf 
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt 

data = keras.dataset_fashion_mnist

(train_images, train_labels), (test_images, test_labels) = data.data_load()

print(train_labels[1])

我应该得到一个数字作为输出,而不是一个错误。

错误是:

Traceback (most recent call last):
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\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:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\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 "helloworld.py", line 1, in <module>
    import tensorflow as tf
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
    from tensorflow_core import *
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\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:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\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.

我不知道该怎么做以及尝试什么。我确保我已经安装了tensorflow并且做到了。 我认为这与它的库iteff有关。

1 个答案:

答案 0 :(得分:0)

您的错误似乎与此类似:https://github.com/tensorflow/tensorflow/issues/22794

通常的解决方案是使用特定版本的CUDA和特定版本的tensorflow,例如

tensorflow-gpu==1.14.0
python 3.6.8
CUDA v10.0
cudnn 7.4.1.5

可以提供您的图书馆版本吗?我建议使用conda在Windows上安装tensorflow,因为它可以帮助安装正确的版本而不是自行设置。

修改

请尝试以下步骤(摘自Tensorflow文档:https://www.tensorflow.org/install/pip

  1. 转到Visual Studio下载:https://visualstudio.microsoft.com/vs/older-downloads/

  2. 选择可再发行文件和构建工具

  3. 下载并安装Microsoft Visual C ++ 2015 Redistributable 更新3

在Windows上启用长路径:https://superuser.com/questions/1119883/windows-10-enable-ntfs-long-paths-policy-option-missing

最后,请确保您的CPU支持AVX指令:https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#CPUs_with_AVX