我已将我的代码从 C 导出到 myexported.dll。 myexported.dll 又依赖于 platforms/qwindows.dll (QT)。与 myexported.dll 在同一目录中
这就是我使用 ctypes 的方式:
#myapp.py
from ctypes import *
mydll = WinDLL("myexported.dll")
mydll.independant_foo() #works fine
mydll.dependant_foo() #prompts the error and exits the program (python.exe)
当我运行脚本时:
python.exe myapp.py
一切正常(非依赖函数),直到它调用需要 qwindows.dll 的函数。此时提示:
This application failed to start because it could not find or load the Qt platform plugin "windows". Available platform plugins are: minimal, offscreen, windows. Reinstalling the application may fix this problem.
我尝试了以下方法,但均无效:
- 手动和使用 os.environ['PATH'] 将 qwindows.dll 的路径添加到环境中
- os.chdir("path/to/platforms/qwindows.dll") 或 os.chdir("path/to/platforms")
- os.path.append("path/to/platforms/qwindows.dll") 或 os.path.append("path/to/platforms")
- 将 qwindows.dll 复制到 myexported.dll 旁边
唯一可行的情况是将“platforms/qwindows.dll”复制到我的 python 文件夹中的 python.exe 文件旁边。
还有10个类似的dll,除非在python.exe文件旁边,否则找不到。
如何强制 python.exe 查看 myapp.py 目录中的 dll?
最佳答案
我遇到了同样的问题。刚刚找到答案:error-when-loading-dll-from-a-different-directory-using-python-ctypes-cdl
简而言之,修改你的 os.environ['PATH']
。
关于python - Ctypes 找不到我加载的 dll 的 dll 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42092890/