TensorFlow ImportError:DLL加载失败,错误代码为-1073741795 问题解决

Categories 机器学习

问题

赛扬J3160 CPU,使用pip install tensorflow安装好tensorflow,运行如下代码,

import tensorflow as tf
import math
import pandas as pd
import numpy as np
from tensorflow.python.data import Dataset
from matplotlib import pyplot as plt
import seaborn as sns

得到错误如下:

ImportError: Traceback (most recent call last):
  File "C:\Users\Administrator.USER-20190627CO\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Administrator.USER-20190627CO\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Administrator.USER-20190627CO\AppData\Local\Programs\Python\Python37\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\Administrator.USER-20190627CO\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\Administrator.USER-20190627CO\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed with error code -1073741795

找到github上有人碰到类似错误,原因是CPU缺少 AVX 指令集支持(看来是赛扬处理器稍低端了)。

解决

解法也很简单,依次执行如下步骤:

  • pip uninstall tensorflow
  • github下不支持AVX指令集的tensorflow轮子。一般选最新版的tensorflow;注意您的python版本,若是3.7,就选1.x.0/py37/CPU/sse2下的wheel
  • 下好到本地后执行“pip install 刚刚下好wheel的本地路径”

版权声明:本站文章除非特别声明,均为L&H原创。允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。

本文链接:TensorFlow ImportError:DLL加载失败,错误代码为-1073741795 问题解决 @ L&H site


发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据