安装Tensorflow 2会导致dll无法在pywrap_tensorflow.py中加载

雷·塔耶克

在过去大约一年的时间内我在这里这里那里安装TensorFlow 2时遇到了问题 所以我在尝试Miniconda。

我有AMD Radeon hd 6670和AMD Radeon hd 6450。

我刚刚下载了Miniconda并制作了一个环境,并pip install --upgrade tensorflow在Windows 8.1上的Miniconda提示符下进行了操作,并获得了TensorFlow 2.2。

当我尝试导入tensorflow时,我得到下面的堆栈跟踪。

我确实下载了Visual Studio,以获取最新的重新分发文件(我认为)。

似乎发生在此行附近: from tensorflow.python.pywrap_tensorflow_internal import *

编辑1:我将这个yaml文件用于python 3.6(另一个是3.7),但是它产生了相同的错误。

编辑2:我升级到Conda 4.8.3和Python 3.7(在yaml文件中),并得到了相同的错误。这是pywrap内部的一行显示问题:

line 28: _pywrap_tensorflow_internal = swig_import_helper()

在痛饮助手中:

fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])

看起来它正在寻找自己吗?有人知道吗?

编辑3:看起来像相同的问题,但它已过时。似乎是使用2015 C ++重新分配解决的相同问题。我确实安装了2015 x64和2015-2019 x86。

编辑4:尝试3.5会收到子流程错误(请参见下文)。

编辑5:尝试用3.7: conda install 'tensorflow=*=mkl*'没有YAML文件)没有工作(3.6确实工作)。不幸的是,导入tf2仍然需要10秒!

搜索:-gpu swig_import_helper“未能加载本机TensorFlow运行时”导致大约3.6k的命中,因此这是一个持续存在的问题。

编辑5:安装Keras会破坏bug。尝试修复该错误:AttributeError: module 'tensorflow' has no attribute 'compat'因此TensorFlow不再起作用。

是否有人拥有可重复的稳定过程?我正在尝试使用Python深度学习第二版中的代码

编辑6:解散minconda花了大约一个小时。安装新的蟒蛇效果很好。使用他们的yaml文件可以很好地安装。但是导入tensorflow会导致dll加载错误。

编辑7:试用Python 3.8并使用虚拟环境快得多。我可以安装TensorFlow。但是使用它会得到:

ImportError: Could not find the DLL(s) 'msvcp140_1.dll'. TensorFlow requires that these DLLs be installed in a directory that is named in your %PATH% environmen
t variable. 

我确实已经安装了可再发行文件,并且路径上有Windows / system32:

(handson-ml2) d:\ray\dev\mlbooks\handson-ml2>echo %PATH%
d:\pyvenvs\handson-ml2\Scripts;C:\Program Files (x86)\Common Files\Oracle\Java\j
avapath;c:\Rtools\bin;c:\Rtools\mingw_32\bin;C:\ProgramData\Oracle\Java\javapath
;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x8
6;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\Wi
ndowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Stati
c;C:\Program Files (x86)\Common Files\Acronis\SnapAPI\;C:\Program Files (x86)\AM
D\ATI.ACE\Core-Static;C:\gnuplot\bin;C:\Program Files\Git\cmd;C:\Program Files\C
alibre2\;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files\MySQL\MySQ
L Utilities 1.6\;C:\Program Files (x86)\Common Files\Acronis\VirtualFile\;C:\Pro
gram Files (x86)\Common Files\Acronis\VirtualFile64\;C:\Program Files (x86)\Comm
on Files\Acronis\FileProtector\;C:\Program Files (x86)\Common Files\Acronis\File
Protector64\;C:\Program Files\nodejs\;C:\Program Files (x86)\Brackets\command;C:
\Program Files\Microsoft VS Code\bin;C:\Users\ray\AppData\Local\Programs\Python\
Launcher\;d:\bin;C:\Users\ray\AppData\Roaming\npm;C:\Users\ray\AppData\Local\ato
m\bin;C:\Program Files (x86)\FAHClient;x:\Program Files\Docker Toolbox

这里这里都是类似的问题。

有些人建议将dll复制到python路径区域。

似乎在一夜之间变成了警告。现在我得到:

(handson-ml2) d:\ray\dev\mlbooks\handson-ml2>py
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-06-25 13:53:13.746994: W tensorflow/stream_executor/platform/default/dso_lo
ader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64
_101.dll not found
2020-06-25 13:53:13.776619: I tensorflow/stream_executor/cuda/cudart_stub.cc:29]
 Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Pip subprocess error:
ERROR: Could not find a version that satisfies the requirement bokeh>=2.0.0 (fro
m panel>=0.7.0->holoviews->-r D:\ray\dev\COVID-19\condaenv.tvdi0rp1.requirements
.txt (line 5)) (from versions: 0.2, 0.3, 0.4, 0.4.1, 0.4.4, 0.5.0, 0.5.1, 0.5.2,
 0.6.0, 0.6.1, 0.7.0, 0.7.1, 0.8.0, 0.8.1, 0.8.2, 0.9.0, 0.9.1, 0.9.2, 0.9.3, 0.
10.0, 0.11.0, 0.11.1, 0.12.0, 0.12.1, 0.12.2, 0.12.3, 0.12.4, 0.12.5, 0.12.6, 0.
12.7, 0.12.9, 0.12.10, 0.12.11, 0.12.13, 0.12.14, 0.12.15, 0.12.16, 0.13.0, 1.0.
0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.1.0, 1.2.0, 1.3.0, 1.3.1, 1.3.2, 1.3.4, 1.4.0)
ERROR: No matching distribution found for bokeh>=2.0.0 (from panel>=0.7.0->holov
iews->-r D:\ray\dev\COVID-19\condaenv.tvdi0rp1.requirements.txt (line 5))


CondaEnvException: Pip failed

这是原始堆栈跟踪:

Traceback (most recent call last):
  File "d:\miniconda3\envs\tf2\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "d:\miniconda3\envs\tf2\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "d:\miniconda3\envs\tf2\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 "d:\miniconda3\envs\tf2\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "d:\miniconda3\envs\tf2\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 "2.py", line 1, in <module>
    import tensorflow as tf
  File "d:\miniconda3\envs\tf2\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "d:\miniconda3\envs\tf2\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "d:\miniconda3\envs\tf2\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "d:\miniconda3\envs\tf2\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "d:\miniconda3\envs\tf2\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "d:\miniconda3\envs\tf2\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 "d:\miniconda3\envs\tf2\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "d:\miniconda3\envs\tf2\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.
卡多兹

现状

在两台机器上可再现地遇到了一个类似的问题(我遇到的最大问题)。例如,这里讨论的一些问题似乎是已知的:1 2 3 4不仅要复制2,还必须开始使用虚拟环境来测试多个tf版本。可以这样实现:(Windows上的virtualenv链接

$ pip install --user pipenv

根据我的知识,可以采取几种方法。

检查版本和兼容性

正如您对其他问题的评论一样,注意分别适合的版本非常重要。我在回答中也谈到了这一点您以哪种方式安装了python版本和anaconda?由于Windows (可能正在使用)上同时存在用户和系统模式选项,因此可能会造成干扰。为了找出答案,您可以在cmd:where anaconda和中键入以下命令where python这将输出系统中找到的位置的列表。如果缺少某些内容,您还PATH可以查看其中添加的天气。

具有相应的版本很重要-请以此处此处2为起点。使用本段第一个链接中的预制车轮,使事情变得更容易,因为您只需要选择正确的版本并安装它即可。第二个链接讨论了tensorflow和python版本的不同组合,这在其他方面可能是可行的。

当有多个不同版本(例如python)时,另一个有用的提示是始终确保使用正确的版本。调用正确的点来安装相应的车轮,然后在cmd中可以如下所示:

C:\Users\XXXXX\AppData\Local\Programs\Python\Python38\Scripts\pip.exe install https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.2.0-cp38-cp38-win_amd64.whl

而下一条命令返回后会在我的系统上给出错误pip 20.1.1 from C:\Users\XXXXX\.conda\envs\tf-cpu-AVX-env\lib\site-packages\pip (python 3.7)(请注意python版本):

pip.exe -V
pip.exe install https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.2.0-cp38-cp38-win_amd64.whl

对于这些示例,将使用来自Google的官方预建车轮。请参阅此站点,其中提供了一些最新的tensorflow软件包。请注意,此示例是既没有GPU也没有AVX的车轮。因为这样的调用容易出错并且有点麻烦,所以建议使用开头或以下内容所提示的虚拟环境:

在虚拟环境中使用(ana)conda

如上所述的虚拟环境不仅使它更加方便,而且组织起来更加紧密。这样做是一个很好的工具。对于anaconda gui,您可以在“ environments”下创建一个新的venv,并将您的python版本设置为例如3.5。GUI中的不同Anaconda环境然后您可以搜索tensorflow软件包并通过环境列表旁边的软件包列表非常容易地安装它。当然,您可能还必须安装其他软件包,例如Pandas,scikit-learn,numpy。

要在命令行上使用Conda,此链接为第一步提供了很好的帮助(同样来自上述其他问题)。

有关此主题的进一步阅读(有关降级tf):这里

检查未满足的依赖关系

For troubleshooting the "DLL load failed" problem on Windows systems, dependencies can be checked with this DLL dependency analyzer tool This comes from the link 4 from the beginning, leading to this post explanation on how to approach DLL load failed problems on Windows. With that, it was discovered on my system that this dynamic library was missing: api-ms-win-core-wow64-11-1-0.dll. 使用上述工具发现了未解决的依赖关系

Adressing Tensorflow CPU/GPU issues

One of the possible sources for your trouble is incompatibilities with Tensorflow-GPU. This is because the default TF package contains both the CPU and GPU versions since the TF 2.1 release.

To check if this causes some of your problems, a CPU-only variant can be tried first. You could for example try to install the correct tensorflow-CPU wheel from here (this is python 3.7 and tensorflow 2.0, decide weather to use AVX or not depending on the capabilities of your processor) or the google source named above.


For Tensorflow-GPU, the following prerequisites have to be met:

Installation of NVIDIA cuDNN (a GPU-accelerated library of primitives for deep neural networks) as e.g. cudnn-11.0-windows-x64-v8.0.1.13 here. After registration for the NVIDIA developer program, this can be accessed here.

Please pay attention to the correct versions for a compatible CUDA Installation - see above! The current Tensorflow (2.2.0, but also true for TF ≥ 2.1.0 as of 23.07.2020) needs

  • CUDA 10.1 and the respective cuDNN ⤷ this is excactly matched only in the cuDNNv7.6.5 of November 5th, 2019, afaik.
  • For Cuda 10.1, a fitting NVIDIA® GPU driver of version 418.x or higher is required. This can be accessed e.g. here but has to be picked according to your platform. (Pay attention to not use a DCH driver where not applicable, see here.)
  • CUPTI, which ships with the CUDA Toolkit.
  • cuDNN SDK (>= 7.6)
  • (Optional) TensorRT 6.0 to improve latency and throughput for inference on some models.

(This is partly taken from here)

In order to install cuDNN (see above), the correct archive has to be downloaded, unzipped and copied from its directory the respective CUDA x.y install location. For windows, the locations for the three files are: (where x.y matches your specific installation as for example 10.2 - more information here and here)

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vx.y\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vx.y\include
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vx.y\lib

Actually, not using the exact CUDA version 10.1 (but e.g. 10.2 instead) will cause errors such as: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found

To test your tensorflow configuration on AVX or GPU availability, you can use this approach.

Using Tensorflow on your GPU

我注意到,您正在使用两个AMD GPU。我不知道带有OpenGL或类似端口的端口,因为它总是谈论CUDA计算功能(参考-张量流应该≥3.5,并且仅适用于NVIDIA GPU)

请参考此答案(或可能也参考其他答案),以解决与缺少CUDA支持有关的问题。

进一步阅读有关为Tensorflow启用GPU的信息:此处

如果以上所有方法均无济于事,则另一种可能的方法是自己从源构建张量流(这也可能导致性能提高)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章