テンソルフローのインポート中にエラーが発生しました!苦痛な教訓!ImportError:DLLのロードに失敗しました:ダイナミックリンクライブラリ(DLL)の初期化ルーチンに失敗しました。ついに解決!

1.問題の原因

  • 環境:win10
  • アナコンダ2020.07.20
  • 仮想環境tf2nlp + python3.7

問題の原因:会社のノートブックを使用したため、そのノートブックの環境をインストールし、Anacondaをインストールし、仮想環境tf2nlpを作成し、仮想環境に入り、インストールする必要がありました:pip install tensorflow==2.0pythonの起動時に、tensorflowをインポートすると、次のエラーが発生します発生した。次に、Microsoftの公式Webサイトにアクセスして、エラーメッセージに従ってダウンロードVC_redist.x64.exeしてインストールしましたが、エラーメッセージは同じままでした。インターネット上の関連記事はすべてtfのバージョンを減らすように言っていますが、ダウングレードは私の考えではありません私はtensorflow2.xを使いたいです私は仕事をしない人です、そしてtf1.xは時代遅れであり、メンテナンスなので、tf2を使用することに決めたので、解決策を見つけることを強く主張し、最後に...(涙と幸せ)
[注:自分のパソコンではすべてが正常です!
エラーは次のとおりです。

ImportError: DLL load failed: 动态链接库(DLL)初始化例程失败。
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda3\envs\tf2nlp\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
    from tensorflow_core import *
  File "C:\Anaconda3\envs\tf2nlp\lib\site-packages\tensorflow_core\__init__.py", line 42, in <module>
    from . _api.v2 import audio
  File "C:\Anaconda3\envs\tf2nlp\lib\site-packages\tensorflow_core\_api\v2\audio\__init__.py", line 10, in <module>
    from tensorflow.python.ops.gen_audio_ops import decode_wav
  File "C:\Anaconda3\envs\tf2nlp\lib\site-packages\tensorflow_core\python\ops\gen_audio_ops.py", line 9, in <module>
    from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
  File "C:\Anaconda3\envs\tf2nlp\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Anaconda3\envs\tf2nlp\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Anaconda3\envs\tf2nlp\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Anaconda3\envs\tf2nlp\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Anaconda3\envs\tf2nlp\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Anaconda3\envs\tf2nlp\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Anaconda3\envs\tf2nlp\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Anaconda3\envs\tf2nlp\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 "C:\Anaconda3\envs\tf2nlp\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Anaconda3\envs\tf2nlp\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 动态链接库(DLL)初始化例程失败。
 
 
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.

2.問題解決プロセス:

  1. その後、すぐにいくつかのdllファイルが欠落していると推測したので、dll修復ソフトウェアを使用して修復しましたが、機能しませんでした。最初の試みは失敗しました。

  2. その後、環境変数、CUDA、CUDNN、バージョンの対応を確認し、仮想環境とテンソルフローを再インストールしました!もちろん、卵は使い物になりません!2回目の失敗。

  3. condaインストールに切り替えると同じエラーが報告されます。
    ここに画像の説明を挿入します

  4. 三度目、Baiduを始めましょう!インターネットには多くの意見があります。テンソルフローのバージョンを減らしたいという意見もあれば、vc64ビットランタイムライブラリのインストールと呼ばれるものもあれば、AVX命令が原因であるものもあれば、64ビット32ビットが原因であるものもあります。 Pythonバージョンが原因です!実際、これらは問題の鍵ではありません!重要なのは、4番目のポイントを見ることです!

  5. その後、時々インポート中に次のエラーが報告されたので、アップグレード前後のh5pyライブラリのバージョンを比較し、アップグレード前後の類似点と相違点を比較したところ、次のことがわかりました。

>>> import tensorflow as tf
C:\Anaconda3\envs\tf2nlp\lib\site-packages\h5py\__init__.py:40: UserWarning: h5py is running against HDF5 1.10.5 when it was built against 1.10.4, this may cause problems
  '{0}.{1}.{2}'.format(*version.hdf5_built_version_tuple)
Warning! ***HDF5 library version mismatched error***
The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as 'LD_LIBRARY_PATH'.
You can, at your own risk, disable this warning by setting the environment
variable 'HDF5_DISABLE_VERSION_CHECK' to a value of '1'.
Setting it to 2 or higher will suppress the warning messages totally.
Headers are 1.10.4, library is 1.10.5
        SUMMARY OF THE HDF5 CONFIGURATION
        =================================

General Information:
-------------------
                   HDF5 Version: 1.10.5
                  Configured on: 2019-03-04
                  Configured by: Visual Studio 15 2017 Win64
                    Host system: Windows-10.0.17763
              Uname information: Windows
                       Byte sex: little-endian
             Installation point: C:/Program Files/HDF5

Compiling Options:
------------------
                     Build Mode:
              Debugging Symbols:
                        Asserts:
                      Profiling:
             Optimization Level:

Linking Options:
----------------
                      Libraries:
  Statically Linked Executables: OFF
                        LDFLAGS: /machine:x64
                     H5_LDFLAGS:
                     AM_LDFLAGS:
                Extra libraries:
                       Archiver:
                         Ranlib:

Languages:
----------
                              C: yes
                     C Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe 19.16.27027.1
                       CPPFLAGS:
                    H5_CPPFLAGS:
                    AM_CPPFLAGS:
                         CFLAGS:  /DWIN32 /D_WINDOWS /W3
                      H5_CFLAGS:
                      AM_CFLAGS:
               Shared C Library: YES
               Static C Library: YES

                        Fortran: OFF
               Fortran Compiler:
                  Fortran Flags:
               H5 Fortran Flags:
               AM Fortran Flags:
         Shared Fortran Library: YES
         Static Fortran Library: YES

                            C++: ON
                   C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe 19.16.27027.1
                      C++ Flags: /DWIN32 /D_WINDOWS /W3 /GR /EHsc
                   H5 C++ Flags:
                   AM C++ Flags:
             Shared C++ Library: YES
             Static C++ Library: YES

                            JAVA: OFF
                   JAVA Compiler:

Features:
---------
                   Parallel HDF5: OFF
Parallel Filtered Dataset Writes:
              Large Parallel I/O:
              High-level library: ON
                    Threadsafety: OFF
             Default API mapping: v110
  With deprecated public symbols: ON
          I/O filters (external):  DEFLATE DECODE ENCODE
                             MPE:
                      Direct VFD:
                         dmalloc:
  Packages w/ extra debug output:
                     API Tracing: OFF
            Using memory checker: OFF
 Memory allocation sanity checks: OFF
          Function Stack Tracing: OFF
       Strict File Format Checks: OFF
    Optimization Instrumentation:
Bye...

>>> import h5py
C:\Anaconda3\envs\tf2nlp\lib\site-packages\h5py\__init__.py:40: UserWarning: h5py is running against HDF5 1.10.5 when it was built against 1.10.4, this may cause problems
  '{0}.{1}.{2}'.format(*version.hdf5_built_version_tuple)
Warning! ***HDF5 library version mismatched error***
The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as 'LD_LIBRARY_PATH'.
You can, at your own risk, disable this warning by setting the environment
variable 'HDF5_DISABLE_VERSION_CHECK' to a value of '1'.
Setting it to 2 or higher will suppress the warning messages totally.
Headers are 1.10.4, library is 1.10.5
        SUMMARY OF THE HDF5 CONFIGURATION
        =================================

General Information:
-------------------
                   HDF5 Version: 1.10.5
                  Configured on: 2019-03-04
                  Configured by: Visual Studio 15 2017 Win64
                    Host system: Windows-10.0.17763
              Uname information: Windows
                       Byte sex: little-endian
             Installation point: C:/Program Files/HDF5

Compiling Options:
------------------
                     Build Mode:
              Debugging Symbols:
                        Asserts:
                      Profiling:
             Optimization Level:

Linking Options:
----------------
                      Libraries:
  Statically Linked Executables: OFF
                        LDFLAGS: /machine:x64
                     H5_LDFLAGS:
                     AM_LDFLAGS:
                Extra libraries:
                       Archiver:
                         Ranlib:

Languages:
----------
                              C: yes
                     C Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe 19.16.27027.1
                       CPPFLAGS:
                    H5_CPPFLAGS:
                    AM_CPPFLAGS:
                         CFLAGS:  /DWIN32 /D_WINDOWS /W3
                      H5_CFLAGS:
                      AM_CFLAGS:
               Shared C Library: YES
               Static C Library: YES

                        Fortran: OFF
               Fortran Compiler:
                  Fortran Flags:
               H5 Fortran Flags:
               AM Fortran Flags:
         Shared Fortran Library: YES
         Static Fortran Library: YES

                            C++: ON
                   C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe 19.16.27027.1
                      C++ Flags: /DWIN32 /D_WINDOWS /W3 /GR /EHsc
                   H5 C++ Flags:
                   AM C++ Flags:
             Shared C++ Library: YES
             Static C++ Library: YES

                            JAVA: OFF
                   JAVA Compiler:

Features:
---------
                   Parallel HDF5: OFF
Parallel Filtered Dataset Writes:
              Large Parallel I/O:
              High-level library: ON
                    Threadsafety: OFF
             Default API mapping: v110
  With deprecated public symbols: ON
          I/O filters (external):  DEFLATE DECODE ENCODE
                             MPE:
                      Direct VFD:
                         dmalloc:
  Packages w/ extra debug output:
                     API Tracing: OFF
            Using memory checker: OFF
 Memory allocation sanity checks: OFF
          Function Stack Tracing: OFF
       Strict File Format Checks: OFF
    Optimization Instrumentation:
Bye...



アップグレードが見つかった後、tensorflowは通常どおりインポートできます
。h5pyをpipでアップグレードしたことに注意してください。もちろん、condaも可能です。

pip install -U h5py

ここに画像の説明を挿入します

>>> import tensorflow
>>> 

読んでいるあなたのお役に立てば幸いです。ワンクリックトリプル接続へようこそ、私はブログで私の間違いのメモのいくつかを共有することを主張します
ここに画像の説明を挿入します

おすすめ

転載: blog.csdn.net/qq_42658739/article/details/109616923