Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ctypes on windows: depending dlls not found

I try to load a shared libraray "R.dll" which depends on "Rblas.dll", both are in the same directory. When I load R.dll with ctypes (a python module which loads shared libraries)

import ctypes
lib = ctypes.CDLL("/path_to_r/bin/i386/R.dll")

I get an error message saying that "Rblas.dll" is not found.

What can I do ? I thought that putting both libs in the same directory is enough.

like image 245
rocksportrocker Avatar asked Oct 26 '25 10:10

rocksportrocker


1 Answers

You may need to add the path that the dlls are located at to the %PATH% environmental variable. While R.DLL is loadng with an explicit path, the search for it's requested RBLAS.DLL is still searching %PATH% for it's location. Since that's a Windows level operation, there's no (easy) way to intercept and modify it from python... so changing %PATH% is required.

Though alternately, you could temporarily os.chdir to the desired directory, load the dlls, and restore the original value of os.getcwd after the dlls have loaded.

like image 83
Eli Collins Avatar answered Oct 27 '25 23:10

Eli Collins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!