python - Ctypes 找不到我加载的 dll 的 dll 依赖项

标签 python c dll runtime ctypes

我已将我的代码从 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/

相关文章:

python - 我如何用这些数据绘制条形图

c - 在线程启动时执行 pthread "pre init"函数

c - 标题每次被#include(ed) 时都进行不同的预处理

c++ - 分配初始化、对齐的内存

html - W8 应用商店应用程序 : Writing UI in HTML and CSS, 并为域/模型使用 C# DLL?

dll - MS-RL 商业应用

python - 根据特定列中的负值或 np.nan 值将数据帧拆分为 block

python - 如何修复 Heroku Dyno 不显示的问题?

python - pip 无法找到带有 M1 芯片的brew 安装的库

c++ - 在另一个线程中创建线程