Errors with (third party) Python modules

Last edited on

Symptoms

You may get an error message dialog like this when importing some Python modules (typically third party Python modules which use native libraries):

Microsoft Visual C++ Runtime Library

Runtime Error!

Program: C:..._squishrunner.exe

R6034

An application has made an attempt to load the C runtime library incorrectly.

Please contact the application's support team for more information.

|OK|

Or you may get error messages like these in Python:

ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

ImportError: DLL load failed: Eine DLL-Initialisierungsroutine ist fehlgeschlagen.

ImportError: DLL load failed: The specified module could not be found.

ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.

Possible Cause #1 - Improper/stray MS VC++ runtime libraries

A regular Python 2.7 installation includes these files in its main directory:

While this is a possible way to distribute the MSVC9 runtime it confuses Windows' runtime linker/loader and results in this error:

Microsoft Visual C++ Runtime Library

Runtime Error!

Program: C:..._squishrunner.exe

R6034

An application has made an attempt to load the C runtime library incorrectly.

Please contact the application's support team for more information.

|OK|

Solution

To avoid confusing Windows one can use this alternative approach to distributing the MSVC9 runtime files:

Possible Cause #2 - Manifest in .pyd file without MSVCRT entry (MSVC8, MSVC9 only)

One of the .pyd files that the module consists of may have an embedded manifest which does not specify the respective MSVCRT (Microsoft Visual C++ runtime).

For example older libxml2 Python 2 bindings contain this .pyd file:

<python>\Lib\site-packages\libxmlmods\libxml2mod.pyd

And this .pyd file contains this embedded manifest which does not specify a CRT:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
  </dependency>
</assembly>

Possible solution #1 - Add MSVCRT dependency to _squishrunner.exe

The simplest solution may be to add a manifest to "<SQUISH_DIR>/bin/_squishrunner.exe which specifies the respective MSVCRT dependency to it.

This can be done using Microsoft's "Manifest Tool" ( mt.exe ). Doing this is explained at Setting manifests .

Here is an example manifest that specifies the MSVC9 C++ runtime:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>

Possible solution #2 - Remove the manifest from *.dll / *.pyd files

A simple solution is to remove the manifest from the respective file(s). Doing this is explained at Removing manifests .

However, even after removing (or adding, see xxx) manifests to *.pyd files the problem may remain, or the error may still occur for other files.

Possible solution #3 - Add MSVCRT dependency to manifest of *.dll / *.pyd files

It may also work to set a manifest with a respective MSVCRT dependency to some or all the *.dll and *.pyd files.

This can be done using Microsoft's "Manifest Tool" ( mt.exe ). Doing this is explained at Setting manifests .

Here is an example manifest that specifies the MSVC9 C++ runtime:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>