我有一個加載'c'dll的python腳本,在使用python 2.7(Anaconda)時可以正常工作。這是我用來測試錯誤的測試腳本:import osimport ctypesctypes.cdll.LoadLibrary(os.path.abspath("a_c_library.dll"))使用python 2.7:執(zhí)行時,此方法工作正常 python test.py。沒有錯誤出現(xiàn),以后我也可以使用該庫。如果我在C#程序中使用IronPython,或者甚至僅使用像這樣的命令行: "C:\Program Files\IronPython 2.7\ipy.exe" test.py或ipy32.exe,都會出現(xiàn)以下錯誤:Traceback (most recent call last): File "test.py", line 3, in <module> File "C:\Program Files\IronPython 2.7\Lib\ctypes\__init__.py", line 445, in LoadLibrary File "C:\Program Files\IronPython 2.7\Lib\ctypes\__init__.py", line 366, in __init__OSError: IronPython.Runtime.Exceptions.OSException: cannot load library **THE ABSOLUTE PATH TO MY DLL WHICH IS CORRECT**為什么在使用IronPython時無法加載庫?我在Windows 10上。同樣,在使用常規(guī)python時,我可以使用該庫,但是IronPython用相同的代碼給我一個錯誤。謝謝你的時間!編輯:我試圖直接使用該代碼從C#加載相同的dll:[DllImport("a_c_library.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "AFunction")]static extern IntPtr Unmanged_AFunction();然后調(diào)用未管理的函數(shù),我得到以下錯誤:System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format.嘗試使用x86和x64構(gòu)建。x64給出了此錯誤:System.DllNotFoundException: 'Unable to load DLL 'a_c_library.dll': The specified module could not be found.即使將dll復(fù)制到與x64 exe相同的位置。
IronPython cdll無法加載庫。如果不使用IronPython,則可以使用
慕工程0101907
2021-04-17 18:42:14