标签归档:dll

ImportError:DLL加载失败:%1不是有效的Win32应用程序。但是DLL在那里

问题:ImportError:DLL加载失败:%1不是有效的Win32应用程序。但是DLL在那里

我的情况非常类似于ImportError上的情况:DLL加载失败:%1不是有效的Win32应用程序,但是答案对我不起作用。

我的Python代码说:

import cv2

但是该行引发了此问题标题中显示的错误。

C:\lib\opencv在这台64位计算机上安装了OpenCV 。我正在使用64位Python。

我的PYTHONPATH变量:PYTHONPATH=C:\lib\opencv\build\python\2.7。该文件夹包含cv2.pyd所有内容。

我的PATH变量:Path=%OPENCV_DIR%\bin;...此文件夹包含39个DLL文件,例如opencv_core246d.dll

OPENCV_DIR具有以下值:OPENCV_DIR=C:\lib\opencv\build\x64\vc11

ImportError上的解决方案:DLL加载失败:%1不是有效的Win32应用程序,表示要向C:\opencv\build\bin\ReleaseWindows PATH环境变量添加新的opencv二进制路径()。但是,如上所示,C:\lib\opencv\build\x64\vc11\bin我的PATH中已经有OpenCV Binaries文件夹()。而且我的OpenCV安装没有任何Release文件夹(build / java下为空)。

关于出什么问题有什么想法吗?我可以告诉Python详细跟踪加载过程吗?究竟要寻找什么DLL?

谢谢,拉斯

编辑:

我只注意到,根据http://www.dependencywalker.com/中,cv2.pydC:\lib\opencv\build\python\2.7为32位,而我运行的机器和Python的是64位。可能是问题所在吗?如果是这样,我在哪里可以找到cv2.pyd的64位版本?

I have a situation very much like the one at ImportError: DLL load failed: %1 is not a valid Win32 application, but the answer there isn’t working for me.

My Python code says:

import cv2

But that line throws the error shown in the title of this question.

I have OpenCV installed in C:\lib\opencv on this 64-bit machine. I’m using 64-bit Python.

My PYTHONPATH variable: PYTHONPATH=C:\lib\opencv\build\python\2.7. This folder contains cv2.pyd and that’s all.

My PATH variable: Path=%OPENCV_DIR%\bin;... This folder contains 39 DLL files such as opencv_core246d.dll.

OPENCV_DIR has this value: OPENCV_DIR=C:\lib\opencv\build\x64\vc11.

The solution at ImportError: DLL load failed: %1 is not a valid Win32 application says to add “the new opencv binaries path (C:\opencv\build\bin\Release) to the Windows PATH environment variable”. But as shown above, I already have the OpenCV binaries folder (C:\lib\opencv\build\x64\vc11\bin) in my PATH. And my OpenCV installation doesn’t have any Release folders (except for an empty one under build/java).

Any ideas as to what’s going wrong? Can I tell Python to verbosely trace the loading process? Exactly what DLL’s is it looking for?

Thanks, Lars

EDIT:

I just noticed that, according to http://www.dependencywalker.com/, the cv2.pyd in C:\lib\opencv\build\python\2.7 is 32-bit, whereas the machine and the Python I’m running are 64-bit. Could that be the problem? And if so, where can I find a 64-bit version of cv2.pyd?


回答 0


回答 1

请检查您使用的python版本是否也是64位。如果没有,那可能就是问题所在。您将使用32位python版本,并且已为OPENCV库安装了64位二进制文​​件。

Please check if the python version you are using is also 64 bit. If not then that could be the issue. You would be using a 32 bit python version and would have installed a 64 bit binaries for the OPENCV library.


回答 2

哇,我发现了这个问题的另一种情况。以上都不起作用。最终,我使用python的功能来内省正在加载的内容。对于python 2.7,这意味着:

import imp
imp.find_module("cv2")

这在Anaconda DLL目录中打开了一个完全意外的“ cv2.pyd”文件,多次卸载/安装尝试均未涉及该文件。Python首先是在那儿寻找的,却找不到我的好安装。我删除了该cv2.pyd文件,然后再次尝试imp.find_module(“ cv2”),python立即找到了正确的文件,并且cv2开始工作。

因此,如果没有其他解决方案对您有用,请确保您使用python内省来查看python尝试加载的文件。

Wow, I found yet another case for this problem. None of the above worked. Eventually I used python’s ability to introspect what was being loaded. For python 2.7 this means:

import imp
imp.find_module("cv2")

This turned up a completely unexpected “cv2.pyd” file in an Anaconda DLL directory that wasn’t touched by multiple uninstall/install attempts. Python was looking there first and not finding my good installation. I deleted that cv2.pyd file and tried imp.find_module(“cv2”) again and python immediately found the right file and cv2 started working.

So if none of the other solutions work for you, make sure you use python introspection to see what file python is trying to load.


回答 3

就我而言,我有64位python,而lxml是错误的版本-我也应该一直使用x64版本。我通过在此处下载lxml的64位版本来解决此问题:

https://pypi.python.org/pypi/lxml/3.4.1

lxml-3.4.1.win-amd64-py2.7.exe

这是一个令人沮丧的问题的最简单答案。

In my case, I have 64bit python, and it was lxml that was the wrong version–I should have been using the x64 version of that as well. I solved this by downloading the 64-bit version of lxml here:

https://pypi.python.org/pypi/lxml/3.4.1

lxml-3.4.1.win-amd64-py2.7.exe

This was the simplest answer to a frustrating issue.


回答 4

我只是遇到了这个问题,原来是因为我使用的是x64版本的opencv文件。尝试了x86,它起作用了。

I just had this problem, it turns it was just because I was using x64 version of the opencv file. Tried the x86 and it worked.


回答 5

如果您的构建系统(在我的情况下为CMake)将文件从复制<name>.dll<name>.pyd,则如果原始文件实际上不是dll,则会出现此错误。就我而言,构建共享库已关闭,因此基础文件实际上是一个*.lib

我通过将pyd文件加载到DependencyWalker中并发现它无效而发现了此错误。

If your build-system (CMake in my case) copies the file from <name>.dll to <name>.pyd, you will get this error if the original file wasn’t actually a dll. In my case, building shared libraries got switched off, so the underlying file was actually a *.lib.

I discovered this error by loading the pyd file in DependencyWalker and finding that it wasn’t valid.


回答 6

我有同样的问题。这是我所做的:

  1. 我从这里下载pywin32 Wheel文件,然后

  2. 我卸载了pywin32模块。要卸载,请在命令提示符中执行以下命令。

    pip uninstall pywin32

  3. 然后,我重新安装了pywin32。要安装它,请在pywin32 wheel文件所在的目录中打开命令提示符。然后执行以下命令。

    pip install <Name of the wheel file with extension> 车轮文件将类似于:piwin32-XXX-cpXX-none-win32.whl

它为我解决了问题。您可能还想尝试一下。希望它也对您有用。

I had the same problem. Here’s what I did:

  1. I downloaded pywin32 Wheel file from here, then

  2. I uninstalled the pywin32 module. To uninstall execute the following command in Command Prompt.

    pip uninstall pywin32

  3. Then, I reinstalled pywin32. To install it, open the Command Prompt in the same directory where the pywin32 wheel file lies. Then execute the following command.

    pip install <Name of the wheel file with extension> Wheel file will be like: piwin32-XXX-cpXX-none-win32.whl

It solvs the problem for me. You may also like to give it a try. Hope it work for you as well.


回答 7

cv2.pyd/opencv/build/python/2.7/x86文件夹而不是从/x64文件夹复制文件到C:/Python27/Lib/site-packeges。我按照此处提供的其余说明进行操作。

由其他人添加,未经验证:我还复制了文件 cv2.pyd到folder C:/Python27/Lib/site-packages/cv2。有用。

I copied cv2.pyd file from /opencv/build/python/2.7/x86 folder instead of from /x64 folder to C:/Python27/Lib/site-packeges. I followed rest of the instructions provided here.

Added by someone else, not verified: I also copy file cv2.pyd to folder C:/Python27/Lib/site-packages/cv2. It works.


回答 8

对我来说,问题是我在同一个 Eclipse项目中使用了不同版本的Python 。我的设置与“ 项目属性”和“ 运行配置” Python版本不一致。

项目>属性> PyDev中,将解释器设置为Python2.7.11。

“运行配置”>“解释器”中,我正在使用“默认解释器”。将其更改为Python 2.7.11可解决此问题。

For me the problem was that I was using different versions of Python in the same Eclipse project. My setup was not consistent with the Project Properties and the Run Configuration Python versions.

In Project > Properties > PyDev, I had the Interpreter set to Python2.7.11.

In Run Configurations > Interpreter, I was using the Default Interpreter. Changing it to Python 2.7.11 fixed the problem.


回答 9

当我使用32位Windows Installer在系统上卸载并重新安装其他版本的2.7.x Python时,遇到了相同的问题。我的大多数导入语句都出现相同的错误。我卸载了新安装的Python,然后下载了64位Windows安装程序,然后再次重新安装了Python,它可以正常工作。希望对您有帮助。

I faced the same issue when I uninstalled and reinstalled a different version of 2.7.x of Python on my system using a 32 bit Windows Installer. I got the same error on most of my import statements. I uninstalled the newly installed Python and downloaded a 64 bit Windows installer and reinstalled Python again and it worked. Hope this helps you.


回答 10

所以我在Windows下安装vtk时遇到问题(由于我使用python 3.7,到目前为止,仅适用于较旧的python版本,没有可用的二进制文件pip install vtk无法正常工作)

我确实在cmd中编写了python:

Python 3.7.3 on win32

所以我现在知道我的python 3.7.3在32位上运行。

然后,我在下载了正确的车轮 VTK-8.2.0-cp37-cp37m-win32.whl

接下来,我安装了该轮子:

pip install VTK-8.2.0-cp37-cp37m-win32.whl

然后,我对其进行了测试并成功运行:

python
import vtk

So I had problems installing vtk under windows (as I use python 3.7 there is no binary available so far just for older python versions pip install vtk is not working)

I did wrote python in my cmd:

Python 3.7.3 on win32

So I now know I have python 3.7.3 runing on a 32 bit.

I then downloaded the correct wheel at VTK‑8.2.0‑cp37‑cp37m‑win32.whl

Next I instlled that wheel:

pip install VTK-8.2.0-cp37-cp37m-win32.whl

Then I tested it and it worked:

python
import vtk

回答 11

更新numpy。

pip install numpy --upgrade

为我工作!

Update numpy.

pip install numpy --upgrade

Work for me!!


回答 12

首先,我cv2.pyd从复制/opencv/build/python/2.7/x86C:/Python27/Lib/site-packeges。错误是

“ RuntimeError:模块是根据API版本9编译的,但此版本的numpy是7”

然后我安装了numpy-1.8.0-win32-superpack-python2.7.exeopencv,并且工作正常。

>>> import cv2
>>> print cv2.__version__
2.4.13

First I copied cv2.pyd from /opencv/build/python/2.7/x86 to C:/Python27/Lib/site-packeges. The error was

“RuntimeError: module compiled against API version 9 but this version of numpy is 7”

Then I installed numpy-1.8.0-win32-superpack-python2.7.exe and opencv works fine.

>>> import cv2
>>> print cv2.__version__
2.4.13

回答 13

您可以opencv官方非官方站点进行安装。

如果使用,请参考问题和问题Anaconda

You can install opencv from official or unofficial sites.

Refer to this question and this issue if you are using Anaconda.


回答 14

  1. 请确保您已安装python 2.7.12或更低版本,否则您肯定会收到此错误。
  2. 如果操作系统为64位,请确保已安装64位Oracle客户端。
  3. 确保用于Python 2.7的Microsoft Visual C ++编译器对于64位Os为64位,对于32位为32位。注意:-如果您的操作系统是64位,则安装所有64位软件包;如果操作系统是32位,则安装32位软件包。
  1. Please make sure that you have installed python 2.7.12 or below version otherwise you will get this error definitely.
  2. Make sure Oracle client is 64 bit installed if OS is 64 Bit.
  3. Make sure Microsoft Visual C++ Compiler for Python 2.7 is 64 for bit for 64 bit Os or 32 bit for 32 bit. Note:- IF ur OS is 64 bit install all package of 64 bit or if Os is 32 bit install 32 bit package.

回答 15

它有一个非常简单的解决方案。安装后的opencv 地方

cv2.pydC:\opencv\build\python\2.7\ **x64**C:\Python27\Lib\site-packages

代替,cv2.pydC:\opencv\build\python\2.7\ **x86**C:\Python27\Lib\site-packages

It has a very simple solution. After installing opencv place

cv2.pyd from C:\opencv\build\python\2.7\ **x64** to C:\Python27\Lib\site-packages

instead of, place cv2.pyd from C:\opencv\build\python\2.7\ **x86** to C:\Python27\Lib\site-packages


回答 16

尝试导入MySQLdb时出现此错误。

对我有用的是卸载Python,然后重新安装。

安装npm(https://www.npmjs.com/get-npm)后出现错误。它所做的一件事是即使我已经安装了Python,也要安装它。

I got this error when trying to import MySQLdb.

What worked for me was to uninstall Python and then reinstall it.

I got the error after installing npm (https://www.npmjs.com/get-npm). One thing it did was install Python even though I already had it.


回答 17

这对我有用。我尝试了不同的方法,但这是我最好的解决方案。

打开命令提示符并键入以下内容; pip install opencv-python。(确保您的互联网已打开)。之后,请尝试再次导入。

This has worked for me. I have tried different methods but this was my best solution.

Open command prompt and type the following; pip install opencv-python. (make sure your internet is on). after that try importing it again.


回答 18

这个跟我一起工作

pip install -- pywin32==227

This one worked with me

pip install -- pywin32==227

回答 19

我找到了解决方案,也许您可​​以尝试使用cmd窗口而不是anaconda提示窗口来开始您的第一笔测试。

I found the solution, maybe you can try to use the cmd window rather than the anaconda prompt window to start you first scrapy test.


如何使用Python中的DLL文件?

问题:如何使用Python中的DLL文件?

DLL从内部使用文件的最简单方法是什么Python

具体来说,如何在编写任何附加包装器C++代码的情况下完成此功能Python

Python与使用第三方库相比,本机功能是首选。

What is the easiest way to use a DLL file from within Python?

Specifically, how can this be done without writing any additional wrapper C++ code to expose the functionality to Python?

Native Python functionality is strongly preferred over using a third-party library.


回答 0

为了易于使用,ctypes是必经之路。

以下ctypes示例来自我编写的实际代码(在Python 2.5中)。到目前为止,这是我找到的最简单的方法来完成您的要求。

import ctypes

# Load DLL into memory.

hllDll = ctypes.WinDLL ("c:\\PComm\\ehlapi32.dll")

# Set up prototype and parameters for the desired function call.
# HLLAPI

hllApiProto = ctypes.WINFUNCTYPE (
    ctypes.c_int,      # Return type.
    ctypes.c_void_p,   # Parameters 1 ...
    ctypes.c_void_p,
    ctypes.c_void_p,
    ctypes.c_void_p)   # ... thru 4.
hllApiParams = (1, "p1", 0), (1, "p2", 0), (1, "p3",0), (1, "p4",0),

# Actually map the call ("HLLAPI(...)") to a Python name.

hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams)

# This is how you can actually call the DLL function.
# Set up the variables and call the Python name with them.

p1 = ctypes.c_int (1)
p2 = ctypes.c_char_p (sessionVar)
p3 = ctypes.c_int (1)
p4 = ctypes.c_int (0)
hllApi (ctypes.byref (p1), p2, ctypes.byref (p3), ctypes.byref (p4))

ctypes东西具有:(所有的C型的数据类型intcharshortvoid*,等等),并且可以通过数值或引用传递。尽管我的示例没有这样做,但它也可以返回特定的数据类型(HLL API通过修改引用传递的变量来返回值)。


就上面显示的特定示例而言,IBM的EHLLAPI是一个相当一致的接口。

所有呼叫传递四个空指针(EHLLAPI将通过第四个参数的指针返回代码回来,一个int是这样,而我指定int的返回类型,我可以放心地忽略它),按照IBM的文档在这里。换句话说,该函数的C变体为:

int hllApi (void *p1, void *p2, void *p3, void *p4)

这使得一个简单的ctypes函数可以执行EHLLAPI库提供的任何功能,但是其他库可能需要为ctypes每个库函数设置一个单独的函数。

从的返回值WINFUNCTYPE是一个函数原型,但是您仍然必须设置更多的参数信息(类型之外)。每个元组中hllApiParams都有一个参数“方向”(1 =输入,2 =输出,依此类推),一个参数名称和一个默认值- ctypes有关详细信息,请参见doco

一旦有了原型和参数信息,就可以创建一个Python“可调用” hllApi函数来调用该函数。您只需创建(所需的变量p1通过p4在我的情况),并调用函数与他们。

For ease of use, ctypes is the way to go.

The following example of ctypes is from actual code I’ve written (in Python 2.5). This has been, by far, the easiest way I’ve found for doing what you ask.

import ctypes

# Load DLL into memory.

hllDll = ctypes.WinDLL ("c:\\PComm\\ehlapi32.dll")

# Set up prototype and parameters for the desired function call.
# HLLAPI

hllApiProto = ctypes.WINFUNCTYPE (
    ctypes.c_int,      # Return type.
    ctypes.c_void_p,   # Parameters 1 ...
    ctypes.c_void_p,
    ctypes.c_void_p,
    ctypes.c_void_p)   # ... thru 4.
hllApiParams = (1, "p1", 0), (1, "p2", 0), (1, "p3",0), (1, "p4",0),

# Actually map the call ("HLLAPI(...)") to a Python name.

hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams)

# This is how you can actually call the DLL function.
# Set up the variables and call the Python name with them.

p1 = ctypes.c_int (1)
p2 = ctypes.c_char_p (sessionVar)
p3 = ctypes.c_int (1)
p4 = ctypes.c_int (0)
hllApi (ctypes.byref (p1), p2, ctypes.byref (p3), ctypes.byref (p4))

The ctypes stuff has all the C-type data types (int, char, short, void*, and so on) and can pass by value or reference. It can also return specific data types although my example doesn’t do that (the HLL API returns values by modifying a variable passed by reference).


In terms of the specific example shown above, IBM’s EHLLAPI is a fairly consistent interface.

All calls pass four void pointers (EHLLAPI sends the return code back through the fourth parameter, a pointer to an int so, while I specify int as the return type, I can safely ignore it) as per IBM’s documentation here. In other words, the C variant of the function would be:

int hllApi (void *p1, void *p2, void *p3, void *p4)

This makes for a single, simple ctypes function able to do anything the EHLLAPI library provides, but it’s likely that other libraries will need a separate ctypes function set up per library function.

The return value from WINFUNCTYPE is a function prototype but you still have to set up more parameter information (over and above the types). Each tuple in hllApiParams has a parameter “direction” (1 = input, 2 = output and so on), a parameter name and a default value – see the ctypes doco for details

Once you have the prototype and parameter information, you can create a Python “callable” hllApi with which to call the function. You simply create the needed variable (p1 through p4 in my case) and call the function with them.


回答 1

该页面有一个非常简单的示例,示例从DLL文件中调用函数。

为了完整起见,在此处解释细节:

在Python中调用DLL函数非常容易。我有一个带有两个函数的自制DLL文件:addsub具有两个参数。

add(a, b)返回两个数字的加法
sub(a, b)返回两个数字的减法

DLL文件的名称将为“ demo.dll”

程序:

from ctypes import*
# give location of dll
mydll = cdll.LoadLibrary("C:\\demo.dll")
result1= mydll.add(10,1)
result2= mydll.sub(10,1)
print "Addition value:"+result1
print "Substraction:"+result2

输出:

Addition value:11
Substraction:9

This page has a very simple example of calling functions from a DLL file.

Paraphrasing the details here for completeness:

It’s very easy to call a DLL function in Python. I have a self-made DLL file with two functions: add and sub which take two arguments.

add(a, b) returns addition of two numbers
sub(a, b) returns substraction of two numbers

The name of the DLL file will be “demo.dll”

Program:

from ctypes import*
# give location of dll
mydll = cdll.LoadLibrary("C:\\demo.dll")
result1= mydll.add(10,1)
result2= mydll.sub(10,1)
print "Addition value:"+result1
print "Substraction:"+result2

Output:

Addition value:11
Substraction:9


回答 2

ctypes可用于访问dll,这是一个教程:

http://docs.python.org/library/ctypes.html#module-ctypes

ctypes can be used to access dlls, here’s a tutorial:

http://docs.python.org/library/ctypes.html#module-ctypes


回答 3

也许与Dispatch

from win32com.client import Dispatch

zk = Dispatch("zkemkeeper.ZKEM") 

其中zkemkeeper是系统上已注册的DLL文件…之后,您可以通过调用函数来访问它们:

zk.Connect_Net(IP_address, port)

Maybe with Dispatch:

from win32com.client import Dispatch

zk = Dispatch("zkemkeeper.ZKEM") 

Where zkemkeeper is a registered DLL file on the system… After that, you can access functions just by calling them:

zk.Connect_Net(IP_address, port)

回答 4

建立DLL并使用ctypes在Python下连结

我提出关于如何建立一个完全样例shared library,并用它在Python借助于ctypes。我考虑Windows并处理DLLs。需要两个步骤:

  1. 从命令行或从IDE使用Visual Studio的编译器生成DLL。
  2. 使用ctypes在Python下链接DLL。

共享库

shared library我考虑的是以下内容,包含在在testDLL.cpp文件中。唯一的功能testDLL只是接收int并打印它。

#include <stdio.h>

extern "C" {

__declspec(dllexport)

void testDLL(const int i) {
    printf("%d\n", i);
}

} // extern "C"

从命令行构建DLL

要从命令行运行一个DLLwithVisual Studio

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\vsdevcmd"

设置包含路径,然后运行

cl.exe /D_USRDLL /D_WINDLL testDLL.cpp /MT /link /DLL /OUT:testDLL.dll

生成DLL。

DLL从IDE 构建

或者,DLL可以使用Visual Studio以下方式构建:

  1. 文件->新建->项目;
  2. 已安装->模板-> Visual C ++-> Windows-> Win32-> Win32Project;
  3. 下一个;
  4. 应用程序类型-> DLL;
  5. 附加选项->空项目(选择);
  6. 附加选项->预编译头(取消选择);
  7. 项目->属性->配置管理器->活动解决方案平台:x64;
  8. 项目->属性-> Configuration Manager->活动解决方案配置:发布。

在Python下链接DLL

在Python下,执行以下操作

import os
import sys
from ctypes import *

lib = cdll.LoadLibrary('testDLL.dll')

lib.testDLL(3)

Building a DLL and linking it under Python using ctypes

I present a fully worked example on how building a shared library and using it under Python by means of ctypes. I consider the Windows case and deal with DLLs. Two steps are needed:

  1. Build the DLL using Visual Studio’s compiler either from the command line or from the IDE;
  2. Link the DLL under Python using ctypes.

The shared library

The shared library I consider is the following and is contained in the testDLL.cpp file. The only function testDLL just receives an int and prints it.

#include <stdio.h>
​
extern "C" {
​
__declspec(dllexport)
​
void testDLL(const int i) {
    printf("%d\n", i);
}
​
} // extern "C"

Building the DLL from the command line

To build a DLL with Visual Studio from the command line run

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\vsdevcmd"

to set the include path and then run

cl.exe /D_USRDLL /D_WINDLL testDLL.cpp /MT /link /DLL /OUT:testDLL.dll

to build the DLL.

Building the DLL from the IDE

Alternatively, the DLL can be build using Visual Studio as follows:

  1. File -> New -> Project;
  2. Installed -> Templates -> Visual C++ -> Windows -> Win32 -> Win32Project;
  3. Next;
  4. Application type -> DLL;
  5. Additional options -> Empty project (select);
  6. Additional options -> Precompiled header (unselect);
  7. Project -> Properties -> Configuration Manager -> Active solution platform: x64;
  8. Project -> Properties -> Configuration Manager -> Active solution configuration: Release.

Linking the DLL under Python

Under Python, do the following

import os
import sys
from ctypes import *

lib = cdll.LoadLibrary('testDLL.dll')

lib.testDLL(3)

回答 5

ctypes将是最容易使用的东西,但是使用不当会使Python崩溃。如果您想快速地做某事,并且小心一点,那就太好了。

我鼓励您查看Boost Python。是的,它要求您编写一些C ++代码并具有C ++编译器,但实际上您无需学习C ++即可使用它,并且可以从Microsoft获得免费的(如啤酒中的)C ++编译器

ctypes will be the easiest thing to use but (mis)using it makes Python subject to crashing. If you are trying to do something quickly, and you are careful, it’s great.

I would encourage you to check out Boost Python. Yes, it requires that you write some C++ code and have a C++ compiler, but you don’t actually need to learn C++ to use it, and you can get a free (as in beer) C++ compiler from Microsoft.


回答 6

如果DLL是COM库类型,则可以使用pythonnet。

pip install pythonnet

然后在您的python代码中,尝试以下操作

import clr
clr.AddReference('path_to_your_dll')

然后根据DLL中的类实例化一个对象,并访问其中的方法。

If the DLL is of type COM library, then you can use pythonnet.

pip install pythonnet

Then in your python code, try the following

import clr
clr.AddReference('path_to_your_dll')

then instantiate an object as per the class in the DLL, and access the methods within it.