Erreur lors de l'importation de tensorflow! Une leçon pénible! ImportError: le chargement de la DLL a échoué: la routine d'initialisation de la bibliothèque de liens dynamiques (DLL) a échoué. Enfin résolu!

1. La source du problème

  • Environnement: win10
  • Anaconda 2020.07.20
  • Environnement virtuel tf2nlp + python3.7

La source du problème: parce que j'ai utilisé le bloc-notes de l'entreprise, j'ai dû installer l'environnement pour ce bloc-notes, installé Anaconda, créé l'environnement virtuel tf2nlp, entré dans l'environnement virtuel, installé :, pip install tensorflow==2.0lors du démarrage de python, importation de tensorflow, l'erreur suivante eu lieu. Ensuite, je suis allé sur le site officiel de Microsoft pour télécharger VC_redist.x64.exeet installer en fonction du message d'erreur , mais le message d'erreur est resté le même. Des articles similaires sur Internet disent tous de réduire la version de tf, mais la rétrogradation n'est pas mon idée, je veux utiliser tensorflow2.x , je suis une personne qui ne va pas travailler , et tf1.x est obsolète et non Maintenance, donc je suis plus déterminé à utiliser tf2, donc j'ai insisté pour trouver une solution, et enfin ... (larmes et heureux)
[Note: Tout est normal sur mon ordinateur personnel! 】 L'
erreur est la suivante:

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. Processus de résolution de problèmes:

  1. Après cela, j'ai immédiatement deviné que certains fichiers dll manquaient, alors j'ai utilisé un logiciel de réparation de dll pour le réparer, mais cela n'a pas fonctionné! La première tentative a échoué.

  2. Après cela, j'ai vérifié les variables d'environnement, CUDA, CUDNN et la correspondance de version, puis réinstallé l'environnement virtuel et tensorflow! Evidemment, les œufs ne servent à rien! Échec pour la deuxième fois.

  3. Passez à l'installation de conda, la même erreur est signalée.
    Insérez la description de l'image ici

  4. Pour la troisième fois, lancez Baidu! Il y a beaucoup d'opinions sur Internet. Certains disent que vous voulez réduire la version de tensorflow, certains sont appelés installation de la bibliothèque d'exécution vc64-bit, certains sont causés par des instructions AVX, certains sont causés par 64 bits 32 bits, et d'autres sont causés par la version python! En fait, ce ne sont pas là la clé du problème! La clé est de regarder le quatrième point!

  5. Après cela, l'erreur suivante a été signalée lors de l'importation accidentelle, puis je suis allé comparer la version de la bibliothèque h5py avant et après la mise à niveau de la version, pour comparer les similitudes et les différences avant et après la mise à niveau, et j'ai trouvé ce qui suit:

>>> 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...



Une fois la mise à niveau trouvée, tensorflow peut être importé normalement:
Notez que j'ai mis à niveau h5py avec pip, bien sûr, conda est également possible.

pip install -U h5py

Insérez la description de l'image ici

>>> import tensorflow
>>> 

J'espère que cela vous sera utile qui lisez. Bienvenue dans la triple connexion en un clic, j'insisterai pour partager certaines de mes notes d'erreur sur le blog
Insérez la description de l'image ici

Je suppose que tu aimes

Origine blog.csdn.net/qq_42658739/article/details/109616923
conseillé
Classement