如何在python中导入.so文件而不会导致%1不是有效的Win32应用程序错误?
我一直在尝试将一些编译的C代码包含在我的python代码中,如下所示:
from ctypes import CDLL
import os
absolute_path = os.path.dirname(os.path.abspath(__file__))
# imports the c library
test_lib_path = absolute_path + '/theories/test.so'
test = CDLL(test_lib_path)
文件是通过编译文件test.c(其中包含代码)创建的。
gcc -o theories/test.so -shared -fPIC -O2 test.c
.SO 代码到Python程序中,以便我可以使用它,但是我会收到以下错误:
OSError: [WinError 193] %1 is not a valid Win32 application
据我所知,这是指我所编译的代码与我的操作系统不兼容,但是我不知道那在哪里会出错(如果有帮助,请使用vs 2022)。
I have been attempting to include some compiled c code into my python code as follows:
from ctypes import CDLL
import os
absolute_path = os.path.dirname(os.path.abspath(__file__))
# imports the c library
test_lib_path = absolute_path + '/theories/test.so'
test = CDLL(test_lib_path)
The .so file was created by compiling the file test.c (which contains no code) and executing the following command:
gcc -o theories/test.so -shared -fPIC -O2 test.c
I would expect this to load the compiled code into the python program so that I can use it, but I get the following error:
OSError: [WinError 193] %1 is not a valid Win32 application
As far as I can tell, this is meant to indicate that my compiled code is not compatible with my operating system, but I have no clue where that would go wrong (using VS 2022 if that helps).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该是您的Python版本为64位,.SO文件为32位。
首先检查Python版本。
您可以尝试
It should be that your python version is 64 bit and the .so file is 32 bit.
Check the python version first.
You can try