如何修复TensorFlow中ImportError: DLL load failed指定模块未找到错误?
修复DeepFaceLab中TensorFlow DLL加载失败的问题
你在使用DeepFaceLab从视频提取图像训练深度人脸模型时,遇到了TensorFlow原生运行时加载失败的错误,具体报错如下:
Process Process-1: Traceback (most recent call last): File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\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 "imp.py", line 243, in load_module File "imp.py", line 343, in load_dynamic 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 "multiprocessing\process.py", line 258, in _bootstrap File "multiprocessing\process.py", line 93, in run File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\DeepFaceLab\core\leras\device.py", line 102, in _get_tf_devices_proc import tensorflow File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\lib\site-packages\tensorflow\__init__.py", line 102, in <module> from tensorflow_core import * File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\lib\site-packages\tensorflow_core\__init__.py", line 28, in <module> from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__ module = self._load() File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\lib\site-packages\tensorflow\__init__.py", line 44, in _load module = _importlib.import_module(self.__name__) File "importlib\__init__.py", line 126, in import_module File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module> from tensorflow.python import pywrap_tensorflow File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\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\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\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 "imp.py", line 243, in load_module File "imp.py", line 343, in load_dynamic ImportError: DLL load failed: The specified module could not be found. Failed to load the native TensorFlow runtime.
修复方案
安装微软VC++运行库
这是最常见的触发原因,TensorFlow依赖的底层DLL需要Visual C运行时支持。下载并安装x64版本的Microsoft Visual C Redistributable for Visual Studio 2015-2019,安装完成后重启电脑。匹配CUDA与cuDNN版本(GPU加速场景)
如果你用GPU训练,TensorFlow、CUDA、cuDNN的版本必须严格对应:- 你的环境是Python3.6,对应TensorFlow 1.x版本,推荐搭配CUDA 10.0和cuDNN 7.6.5;
- 将cuDNN解压后的
bin、include、lib文件夹复制到CUDA安装目录的对应文件夹中; - 把CUDA的
bin目录(比如C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin)添加到系统环境变量PATH的最顶端,避免版本冲突。
修复自带Python环境中的TensorFlow
自带的Python环境可能存在TensorFlow损坏的情况:- 打开命令提示符,进入DeepFaceLab自带Python的Scripts目录:
cd C:\Users\USER\Desktop\DeepFaceLab_DirectX12\_internal\python-3.6.8\Scripts; - 卸载现有TensorFlow:
pip uninstall tensorflow tensorflow-core -y; - 重新安装对应版本:
pip install tensorflow==1.15.0。
- 打开命令提示符,进入DeepFaceLab自带Python的Scripts目录:
检查系统环境变量
确保以下路径已添加到系统PATH中:- CUDA的
bin和libnvvp目录; - cuDNN的
bin目录; - DeepFaceLab自带Python的
Scripts目录。
- CUDA的
更换DeepFaceLab版本
如果以上方法都无效,尝试更换DeepFaceLab版本,比如选择CPU版本或者更新的GPU通用版本,避开DirectX12版本的兼容性问题。
内容的提问来源于stack exchange,提问作者Raymond
相关产品推荐
相关产品推荐

