OSError: [WinError 193] %1 is not a valid Win32 application in CTypes

Viewed 464

I'm trying to use CTypes to call a C function from Python, but keep getting this error: OSError: [WinError 193] %1 is not a valid Win32 application. I'm using the WSL to compile the C file into a .so file using this command: gcc -fPIC -shared -o libtest.so test.c and have this Python code:

from ctypes import *


lib = CDLL('./libtest.so')
print(lib.square(5))

I can run the Python file using the WSL, but I can't run it using an Anaconda environment from PyCharm. I'm guessing the error is due to the C object being created in the WSL. Is there a way to fix the error and make it so I can compile the C files on the WSL and use the compiled object files in an Anaconda environment?

1 Answers
Related