I am trying to run a C function in Python. I followed examples online, and compiled the C source file into a .so shared library, and tried to pass it into the ctypes CDLL() initializer function.
import ctypes
cFile = ctypes.CDLL("libchess.so")
At this point python crashes with the message:
Could not find module 'C:\Users\user\PycharmProjects\project\libchess.so' (or one of its dependencies). Try using the full path with constructor syntax
.
libchess.so is in the same directory as this Python file, so I don't see why there would be an issue finding it.
I read some stuff about how shared libraries might be hidden from later versions of python, but the suggested solutions I tried did not work. Most solutions were also referring to fixes involving linux system environment variables, but I'm on Windows.
Things I've tried that have not worked:
- changing "libchess.so" to "./libchess.so" or the full path
- using cdll.LoadLibrary() instead of CDLL() (apparently both do the same thing)
- adding the parent directory to system PATH variable
- putting
os.add_dll_directory(os.getcwd())
in the code before trying to load the file
Any more suggestions are appreciated.