A way to narrow down `A dynamic link library (DLL) initialization routine failed.`

Hi! I’ve stumbled upon some user having DLL load failed while importing bsdf: A dynamic link library (DLL) initialization routine failed. error when they import pyradiance library.
The library itself is not important, I guess it’s more general question on how to narrow it down and fix.

There’s a bit of investigation by the link above, I’ll summarize things we tried:

  • the problem started with Python bundled with Blender, but it can reproduced by user with import pyradiance in their system Python 3.11
  • Microsoft Visual C++ Redistributable is up to date
  • bsdf.pyd dependencies, the only file that’s failing to load - link to image
  • running python -v -c "import pyradiance" got us no clues. Link
  • user’s msvcp140.dll version matches with mine, so it shouldn’t be a problem - link
  • user recorded procmon logs on import pyradiance - link, but couldn’t narrow down the issue based on those logs. The only thing I’ve noticed is:

From the logs it seems to find MSVCP140.dll just fine from System32 and VCRUNTIME140_1.dll from Python directory, but it never gets to VCRUNTIME140.dll (doesn’t even check if it exists and never fails, on my system it’s checking python311.dll and then VCRUNTIME140.dll right after finishing with VCRUNTIME140_1.dll and MSVCP140.dll ).

Any other clues we’ve missed or other things to try out?
I’ll invite user with this issue here, so they can try new suggestions in their environment. Perhaps, we’ll be able to solve it.

dlltracer can sometimes help see into what the library loader is trying/failing to do.

1 Like

What else is installed in Blender’s Python 3.11? Does Blender’s Python allow the user to create venvs? I’ve done a lot with Rhino, and a frequent issue for users (before Python 3 and venvs were supported) was dependency clashes between different third party plug-ins, all sharing the same Python environment. 4 times out of 10, Numpy was involved.

User can reproduce the problem with their system’s Python 3.11 too, so it must be something about the general windows system environment.

pip install "numpy<1.27"
pip install pyradiance --no-deps
# DLL load failed while importing bsdf: A dynamic link library (DLL) initialization routine failed.
python -v -c "import pyradiance"

I am one of the ones having the issue with the pyradiance in various blender versions it’s strange only one specific plugin/addon while every other addon works perfectly fine.
I have linked the logs that were given, they can be found at the link where Andrej used but just in case it makes it easier to see: first one is a Logfile.PML file, the second is a text file containing the log that was given in python itself.

It still works for me with numpy 1.26.4:

(pyradiance_py311) C:\...>uv pip uninstall numpy
Using Python 3.11.13 environment at: C:\...\venvs\pyradiance_py311
Uninstalled 1 package in 1.34s
 - numpy==2.2.4

(pyradiance_py311) C:\...>uv pip install "numpy<1.27"
Using Python 3.11.13 environment at: C:\...\venvs\pyradiance_py311
Resolved 1 package in 383ms
Prepared 1 package in 15.95s
Installed 1 package in 4.95s
 + numpy==1.26.4

(pyradiance_py311) C:\...>python test_pyradiance.py
...
Detected executable: C:\...\venvs\pyradiance_py311\Scripts\python.exe
Test dependency installation was successful!

dlltracer looks interesting, thank your for the suggestion.

@Flamesofshadow can you please run try dlltracer and show it’s output?

  1. Install it
pip install dlltracer
  1. Open __init__.py in installed pyradiance and replace the line
from .bsdf import spec_xyz, xyz_rgb

with

import dlltracer
import sys

with dlltracer.Trace(out=sys.stdout):
    from .bsdf import spec_xyz, xyz_rgb
  1. Then open cmd as administrator and run python -c "import pyradiance".

  2. Results I’m getting (you can try to run it multiple times, sometimes output is a bit different):

LoadLibrary C:\Windows\System32\kernel.appcore.dll
LoadLibrary L:\Software\uv\systemvenv\.venv\Lib\site-packages\pyradiance\bsdf.cp311-win_amd64.pyd
LoadLibrary C:\Windows\System32\msvcp140.dll
LoadLibrary L:\Software\Python311\vcruntime140_1.dll

it took me awhile as i had some issues to sort out, i had to set python back to 3.11 in the environment path because for some reason it keeps going back to 3.13 even though pyradiance is set to 3.11.
anyway, i did all the steps mentioned and it gave this:

LoadLibrary C:\Users\.....\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyradiance\bsdf.cp311-win_amd64.pyd
LoadLibrary C:\Windows\System32\msvcp140.dll
LoadLibrary C:\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll
LoadLibrary C:\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll
Failed \Device\HarddiskVolume3\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll
Failed \Device\HarddiskVolume3\Windows\System32\msvcp140.dll
Failed \Device\HarddiskVolume3\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll
Failed \Device\HarddiskVolume3\Users\.....\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyradiance\bsdf.cp311-win_amd64.pyd
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\.....\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyradiance\__init__.py", line 15, in <module>
    from .bsdf import spec_xyz, xyz_rgb
ImportError: DLL load failed while importing bsdf: A dynamic link library (DLL) initialization routine failed.
1 Like

Check this file hasn’t been corrupted:

C:\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll

i checked and it did have a difference in the hash between the python version and system version, but i corrected that and im still getting the same issue.

LoadLibrary C:\Users\.....\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyradiance\bsdf.cp311-win_amd64.pyd
LoadLibrary C:\Windows\System32\msvcp140.dll
LoadLibrary C:\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll
Failed \Device\HarddiskVolume3\Windows\System32\msvcp140.dll
Failed \Device\HarddiskVolume3\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll
Failed \Device\HarddiskVolume3\Users\.....\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyradiance\bsdf.cp311-win_amd64.pyd
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\.....\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyradiance\__init__.py", line 15, in <module>
    from .bsdf import spec_xyz, xyz_rgb
ImportError: DLL load failed while importing bsdf: A dynamic link library (DLL) initialization routine failed.

Are you able to load each of those libraries in isolation?

ctypes.CDLL(r"C:\Windows\System32\msvcp140.dll")
ctypes.CDLL(r"C:\Users\xxx\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll")

i tested both and both said they were ok.

C:\Users\....>py -3.11 -c "import ctypes; ctypes.CDLL(r'C:\Windows\System32\msvcp140.dll'); print('msvcp140.dll loaded OK')"
msvcp140.dll loaded OK

C:\Users\.....>py -3.11 -c "import ctypes; ctypes.CDLL(r'C:\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll'); print('vcruntime140_1.dll loaded OK')"
vcruntime140_1.dll loaded OK
1 Like

Is this a problem similar to this?

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

Perhaps some CPU instruction used in bsdf is not supported.

1 Like

from what i can see it does look similar in stuff trying to load but failing, but i do not think it is cpu related as tests show that the dlls load but not when pyradiance does it so it, however i am not knowledgeable enough to know for sure.

If this is a CPU related problem, compiling pyradiance without any optimization might work.

Sysinternals/CoreInfo can be used to check CPU features.

Intel Software Development Emulator might also be useful to check if the program runs successfully on other CPU.

> path/to/sde.exe -future -- python.exe -c "import pyradiance; print('ok')"

i will send this in chunks to make it easier to distinguish.
here are the CPU/coreinfo results:

Copyright (C) 2008-2022 Mark Russinovich
Sysinternals - www.sysinternals.com


Intel(R) Pentium(R) Silver J5040 CPU @ 2.00GHz
Intel64 Family 6 Model 122 Stepping 8, GenuineIntel
Microcode signature: 00000020
HTT             *       Hyperthreading enabled
CET             -       Supports Control Flow Enforcement Technology
Kernel CET      -       Kernel-mode CET Enabled
User CET        -       User-mode CET Allowed
HYPERVISOR      -       Hypervisor is present
VMX             *       Supports Intel hardware-assisted virtualization
SVM             -       Supports AMD hardware-assisted virtualization
X64             *       Supports 64-bit mode

SMX             -       Supports Intel trusted execution
SKINIT          -       Supports AMD SKINIT
SGX             *       Supports Intel SGX

NX              *       Supports no-execute page protection
SMEP            *       Supports Supervisor Mode Execution Prevention
SMAP            *       Supports Supervisor Mode Access Prevention
PAGE1GB         *       Supports 1 GB large pages
PAE             *       Supports > 32-bit physical addresses
PAT             *       Supports Page Attribute Table
PSE             *       Supports 4 MB pages
PSE36           *       Supports > 32-bit address 4 MB pages
PGE             *       Supports global bit in page tables
SS              *       Supports bus snooping for cache operations
VME             *       Supports Virtual-8086 mode
RDWRFSGSBASE    *       Supports direct GS/FS base access

FPU             *       Implements i387 floating point instructions
MMX             *       Supports MMX instruction set
MMXEXT          -       Implements AMD MMX extensions
3DNOW           -       Supports 3DNow! instructions
3DNOWEXT        -       Supports 3DNow! extension instructions
SSE             *       Supports Streaming SIMD Extensions
SSE2            *       Supports Streaming SIMD Extensions 2
SSE3            *       Supports Streaming SIMD Extensions 3
SSSE3           *       Supports Supplemental SIMD Extensions 3
SSE4a           -       Supports Streaming SIMDR Extensions 4a
SSE4.1          *       Supports Streaming SIMD Extensions 4.1
SSE4.2          *       Supports Streaming SIMD Extensions 4.2

AES             *       Supports AES extensions
AVX             -       Supports AVX instruction extensions
AVX2            -       Supports AVX2 instruction extensions
AVX-512-F       -       Supports AVX-512 Foundation instructions
AVX-512-DQ      -       Supports AVX-512 double and quadword instructions
AVX-512-IFAMA   -       Supports AVX-512 integer Fused multiply-add instructions
AVX-512-PF      -       Supports AVX-512 prefetch instructions
AVX-512-ER      -       Supports AVX-512 exponential and reciprocal instructions
AVX-512-CD      -       Supports AVX-512 conflict detection instructions
AVX-512-BW      -       Supports AVX-512 byte and word instructions
AVX-512-VL      -       Supports AVX-512 vector length instructions
FMA             -       Supports FMA extensions using YMM state
MSR             *       Implements RDMSR/WRMSR instructions
MTRR            *       Supports Memory Type Range Registers
XSAVE           *       Supports XSAVE/XRSTOR instructions
OSXSAVE         *       Supports XSETBV/XGETBV instructions
RDRAND          *       Supports RDRAND instruction
RDSEED          *       Supports RDSEED instruction

CMOV            *       Supports CMOVcc instruction
CLFSH           *       Supports CLFLUSH instruction
CX8             *       Supports compare and exchange 8-byte instructions
CX16            *       Supports CMPXCHG16B instruction
BMI1            -       Supports bit manipulation extensions 1
BMI2            -       Supports bit manipulation extensions 2
ADX             -       Supports ADCX/ADOX instructions
DCA             -       Supports prefetch from memory-mapped device
F16C            -       Supports half-precision instruction
FXSR            *       Supports FXSAVE/FXSTOR instructions
FFXSR           -       Supports optimized FXSAVE/FSRSTOR instruction
MONITOR         *       Supports MONITOR and MWAIT instructions
MOVBE           *       Supports MOVBE instruction
ERMSB           *       Supports Enhanced REP MOVSB/STOSB
PCLMULDQ        *       Supports PCLMULDQ instruction
POPCNT          *       Supports POPCNT instruction
LZCNT           -       Supports LZCNT instruction
SEP             *       Supports fast system call instructions
LAHF-SAHF       *       Supports LAHF/SAHF instructions in 64-bit mode
HLE             -       Supports Hardware Lock Elision instructions
RTM             -       Supports Restricted Transactional Memory instructions

DE              *       Supports I/O breakpoints including CR4.DE
DTES64          *       Can write history of 64-bit branch addresses
DS              *       Implements memory-resident debug buffer
DS-CPL          *       Supports Debug Store feature with CPL
PCID            -       Supports PCIDs and settable CR4.PCIDE
INVPCID         -       Supports INVPCID instruction
PDCM            *       Supports Performance Capabilities MSR
RDTSCP          *       Supports RDTSCP instruction
TSC             *       Supports RDTSC instruction
TSC-DEADLINE    *       Local APIC supports one-shot deadline timer
TSC-INVARIANT   *       TSC runs at constant rate
xTPR            *       Supports disabling task priority messages

EIST            *       Supports Enhanced Intel Speedstep
ACPI            *       Implements MSR for power management
TM              *       Implements thermal monitor circuitry
TM2             *       Implements Thermal Monitor 2 control
APIC            *       Implements software-accessible local APIC
x2APIC          *       Supports x2APIC

CNXT-ID         -       L1 data cache mode adaptive or BIOS

MCE             *       Supports Machine Check, INT18 and CR4.MCE
MCA             *       Implements Machine Check Architecture
PBE             *       Supports use of FERR#/PBE# pin

PSN             -       Implements 96-bit processor serial number

PREFETCHW       *       Supports PREFETCHW instruction

Maximum implemented CPUID leaves: 00000018 (Basic), 80000008 (Extended).
Maximum implemented address width: 48 bits (virtual), 39 bits (physical).

Processor signature: 000706A8

Logical to Physical Processor Map:
*---  Physical Processor 0
-*--  Physical Processor 1
--*-  Physical Processor 2
---*  Physical Processor 3

Logical Processor to Socket Map:
****  Socket 0

Logical Processor to NUMA Node Map:
****  NUMA Node 0

No NUMA nodes.

Logical Processor to Cache Map:
*---  Data Cache          0, Level 1,   24 KB, Assoc   6, LineSize  64
*---  Instruction Cache   0, Level 1,   32 KB, Assoc   8, LineSize  64
****  Unified Cache       0, Level 2,    4 MB, Assoc  16, LineSize  64
-*--  Data Cache          1, Level 1,   24 KB, Assoc   6, LineSize  64
-*--  Instruction Cache   1, Level 1,   32 KB, Assoc   8, LineSize  64
--*-  Data Cache          2, Level 1,   24 KB, Assoc   6, LineSize  64
--*-  Instruction Cache   2, Level 1,   32 KB, Assoc   8, LineSize  64
---*  Data Cache          3, Level 1,   24 KB, Assoc   6, LineSize  64
---*  Instruction Cache   3, Level 1,   32 KB, Assoc   8, LineSize  64

Logical Processor to Group Map:
****  Group 0

here is what intel software development emulator gave:

Traceback (most recent call last): File “”, line 1, in File “C:\Users.…\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyradiance_init_.py”, line 14, in with dlltracer.Trace(out=sys.stdout): File “_native.pyx”, line 300, in dlltracer._native.Trace.enter File “_native.pyx”, line 321, in dlltracer._native.Trace.start File “_native.pyx”, line 201, in dlltracer._native._check PermissionError: [WinError 5] failed to start trace (0x00000005)

and this is from a final test of: py -3.11 -c “import pyradiance; print(‘ok import succeeded’)” which shows that nothing has changed

LoadLibrary C:\Windows\System32\kernel.appcore.dll LoadLibrary C:\Users\.....\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyradiance\bsdf.cp311-win_amd64.pyd LoadLibrary C:\Windows\System32\msvcp140.dll LoadLibrary C:\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll LoadLibrary C:\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll Failed \Device\HarddiskVolume3\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll Failed \Device\HarddiskVolume3\Windows\System32\msvcp140.dll Failed \Device\HarddiskVolume3\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll Failed \Device\HarddiskVolume3\Users\.....\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyradiance\bsdf.cp311-win_amd64.pyd Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\.....\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyradiance\__init__.py", line 15, in <module> from .bsdf import spec_xyz, xyz_rgb ImportError: DLL load failed while importing bsdf: A dynamic link library (DLL) initialization routine failed.

Could you try sde without dlltracer?

if i did it correctly. this is the result:

LoadLibrary C:\Users\.....\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyradiance\bsdf.cp311-win_amd64.pyd
LoadLibrary C:\Windows\System32\msvcp140.dll
LoadLibrary C:\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll
LoadLibrary C:\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll
Failed \Device\HarddiskVolume3\Users\.....\AppData\Local\Programs\Python\Python311\vcruntime140_1.dll
BSDF loaded: <module 'pyradiance.bsdf' from 'C:\\Users\\.....\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\pyradiance\\bsdf.cp311-win_amd64.pyd'