首页 > 解决方案 > 在 Pycharm 中加载原生 TensorFlow 运行时失败

问题描述

这是我目前在 PyCharm 项目中运行的

Windows 10
PyCharm 2020.1.1 (Community Edition)
Python 3.7.7
TensorFlow 2.2.0

这就是我在导入方面的代码:

import math
import pandas_datareader as web
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, LSTM
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')

以下是错误......

H:\Python\AI\venv\lib\site-packages\pandas_datareader\compat\__init__.py:7:
FutureWarning: pandas.util.testing is deprecated. Use the functions in
the public API at pandas.testing instead.   from pandas.util.testing
import assert_frame_equal Using TensorFlow backend. Traceback (most
recent call last):   File
"H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *   File "H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()   File "H:\Python\AI\venv\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\Chan\AppData\Local\Programs\Python\Python37\lib\imp.py",
line 242, in load_module
    return load_dynamic(name, filename, file)   File "C:\Users\Chan\AppData\Local\Programs\Python\Python37\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 "H:/Python/AI/LSMT.py", line
7, in <module>
    from keras.models import Sequential   File "H:\Python\AI\venv\lib\site-packages\keras\__init__.py", line 3, in
<module>
    from . import utils   File "H:\Python\AI\venv\lib\site-packages\keras\utils\__init__.py", line 6,
in <module>
    from . import conv_utils   File "H:\Python\AI\venv\lib\site-packages\keras\utils\conv_utils.py", line
9, in <module>
    from .. import backend as K   File "H:\Python\AI\venv\lib\site-packages\keras\backend\__init__.py", line
1, in <module>
    from .load_backend import epsilon   File "H:\Python\AI\venv\lib\site-packages\keras\backend\load_backend.py",
line 90, in <module>
    from .tensorflow_backend import *   File "H:\Python\AI\venv\lib\site-packages\keras\backend\tensorflow_backend.py",
line 5, in <module>
    import tensorflow as tf   File "H:\Python\AI\venv\lib\site-packages\tensorflow\__init__.py", line 41,
in <module>
    from tensorflow.python.tools import module_util as _module_util   File
"H:\Python\AI\venv\lib\site-packages\tensorflow\python\__init__.py",
line 50, in <module>
    from tensorflow.python import pywrap_tensorflow   File "H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 69, in <module>
    raise ImportError(msg) ImportError: Traceback (most recent call last):   File
"H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *   File "H:\Python\AI\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()   File "H:\Python\AI\venv\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\Chan\AppData\Local\Programs\Python\Python37\lib\imp.py",
line 242, in load_module
    return load_dynamic(name, filename, file)   File "C:\Users\Chan\AppData\Local\Programs\Python\Python37\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.

Process finished with exit code 1

我必须尝试卸载、重新安装、升级、从 Python 3.8 更改为 3.7,...,但仍然出现错误。

标签: pythonpython-3.xtensorflowkeras

解决方案


这是版本问题。

我将 TensorFlow 更改为 1.15,出现 cudart64_100 错误。

然后我用 cudart64_101.dll 安装了 CUDA 10.1 问题仍然存在。

然后我就关注了这个帖子......

https://www.joe0.com/2019/10/19/how-resolve-tensorflow-2-0-error-could-not-load-dynamic-library-cudart64_100-dll-dlerror-cudart64_100-dll-not-成立/

下载,解压OP提供的cudart64_100.dll....

重新安装 TensorFlow 2.0.0。重新启动了我的电脑。问题解决了。

只有未来警告;但没什么大不了的。我现在可以运行我的程序了。

\pandas_datareader\compat\__init__.py:7: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.
from pandas.util.testing import assert_frame_equal
Using TensorFlow backend.

推荐阅读