本文介绍了Windows 上的 Tensorflow 安装:导入 _pywrap_tensorflow_internal 时 DLL 加载失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 上运行了 TensorFlow 对象检测安装.

https://medium.com/riow/tensorflow-object-detection-on-windows-ad10bfde217c

成功安装TensorFlow对象检测后,

我运行以下命令进行测试,并在下面收到错误.如何解决这个问题?

python object_detection/builders/model_builder_test.py

错误:回溯(最近一次调用最后一次):文件C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",第 64 行,在从 tensorflow.python._pywrap_tensorflow_internal 导入 *导入错误:导入 pywrap_tensorflow_internal 时 DLL 加载失败:找不到指定的模块.回溯(最近一次调用最后一次):文件object_detection/builders/model_builder_test.py",第 21 行,在从 object_detection.builders 导入 model_builder文件c:\testimage\models\research\object_detection\builders\model_builder.py",第 23 行,在从 object_detection.builders 导入 anchor_generator_builder文件c:\testimage\models\research\object_detection\builders\anchor_generator_builder.py",第 23 行,在从 object_detection.anchor_generators 导入 flexible_grid_anchor_generator文件c:\testimage\models\research\object_detection\anchor_generators\flexible_grid_anchor_generator.py",第 17 行,在将 tensorflow.compat.v1 导入为 tf文件C:\TestImage\models\venv\lib\site-packages\tensorflow_init.py",第 41 行,在从 tensorflow.python.tools 导入 module_util 作为 module_util文件C:\TestImage\models\venv\lib\site-packages\tensorflow\python_init.py",第 40 行,在从 tensorflow.python.eager 导入上下文文件C:\TestImage\models\venv\lib\site-packages\tensorflow\python\eager\context.py",第 35 行,在从 tensorflow.python 导入 pywrap_tfe文件C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tfe.py",第 28 行,在从 tensorflow.python 导入 pywrap_tensorflow文件C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",第 83 行,在引发导入错误(味精)导入错误:回溯(最近一次调用最后一次):文件C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",第 64 行,在从 tensorflow.python._pywrap_tensorflow_internal 导入 *导入错误:导入 _pywrap_tensorflow_internal 时 DLL 加载失败:找不到指定的模块.

目前使用 Python 3.8 和最新的 tensorflow,以及 tensorflow-cpu

解决方案

tldr;

在安装 TensorFlow 之前,您需要安装 在安装页面上 提到的 C++ 可再发行组件 以便 TensorFlow 可以在安装时使用它生成代码.

详情:

我不是专家,但听起来这很关键:

您缺少的 pywrap_tensorflow_internal.py 模块在我看来是 SWIG 生成的 C++ 库的 Python 接口,或者类似的东西.我的猜测是,当您安装 TensorFlow 时会生成该文件(这让我想起了一些 Ruby gems 在您安装它们时必须如何编译 C++,无论其价值如何).由于您没有生成的文件,我的猜测是该代码生成需要 TensorFlow 安装页面上提到的 C++ 包,因此您需要在安装 TensorFlow 之前安装 C++ 包.

完全是猜测,但也许你在 TF 之后安装了 C++ 包.在这种情况下,您应该可以卸载 TF,安装 C++ 包,然后重新安装 TF.

也许一个挥之不去的问题是在安装 TF 时是否有任何关于缺少 C++ 包的指示性错误消息,如果没有,也许应该有.

I ran through the TensorFlow object detection installation on Windows.

https://medium.com/riow/tensorflow-object-detection-on-windows-ad10bfde217c

After successfully installing TensorFlow object detection,

I ran following command to test, and receiving error below. How can this be fixed?

python object_detection/builders/model_builder_test.py

Currently using Python 3.8 with latest tensorflow, with tensorflow-cpu

解决方案

tldr;

You need to install the C++ redistributable mentioned on the install page before installing TensorFlow so that TensorFlow can use it to generate code at install time.

Details:

I'm not an expert but it sounds like this was key:

The pywrap_tensorflow_internal.py module you are missing appears to me to be a SWIG-generated python interface to a C++ library, or something of that nature. My guess is, that file gets generated when you install TensorFlow (it reminds me of how some Ruby gems have to compile C++ when you install them, for whatever that's worth). Since you don't have that generated file, my guess is that the C++ package mentioned on the TensorFlow install page is needed for that code generation, so you need to have the C++ package installed before installing TensorFlow.

Totally a guess, but perhaps you installed the C++ package after TF. In that case, you should be able to uninstall TF, install the C++ package, and then install TF again.

Maybe a lingering question is if there were any indicative error messages on installing TF about the missing C++ package and if not, maybe there should be.

这篇关于Windows 上的 Tensorflow 安装:导入 _pywrap_tensorflow_internal 时 DLL 加载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:24