【问题标题】:Embded Python Import Ctypes fails嵌入式 Python 导入 Ctypes 失败
【发布时间】:2015-08-13 09:31:30
【问题描述】:

我正在使用 python 2.7 使用 Python for .Net,我将所有需要的目录从 Python2.7 复制到我的应用程序目录中 当我尝试在交互式 shell 中导入 ctypes 时

import ctypes

错误是

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\TesetPyNet\bin\Debug\lib\ctypes\__init__.py", line 10, in <module>
    from _ctypes import Union, Structure, Array
ImportError: DLL load failed: The specified module could not be found.

我要问的是有没有办法设置 Dll 文件夹的路径。

注意:当我将 python 3.4.3 嵌入到我的 c# 应用程序中并将 python 运行时目录复制到我的应用程序目录中时,它可以很好地导入 ctypes,即使在尚未安装 python 版本的操作系统上也是如此

【问题讨论】:

  • 失败不仅是在导入 ctypes 时,而且在我导入任何模块时都需要 Dll 文件夹中的内置模块
  • 正在寻找扩展模块_ctypes.pyd,一般在Python27\DLLs
  • 它在 Python\DLLs 中的奇怪之处

标签: c# python ctypes


【解决方案1】:

经过一些挖掘和检查,_ctypes.pyd 只不过是特定于操作系统的(动态链接库'for windows'-共享对象'for UNIX like')

所以当我检查它的依赖项时,不像 python27.dll 依赖于 msvcr100.dll。它依赖于 msvcr90.dll

所以解决方案是只将 msvcr90.dll 复制到应用程序的工作目录或 DLLs 目录中,在 _ctypes.pyd 旁边

【讨论】:

  • 官方python27.dll与msvcr90.dll链接。您是否使用 VS 2010 自己构建了 python27.dll,如果是,为什么不构建扩展模块?
  • 是的,可能是这样,在 c# 应用程序中运行 python 代码时,我必须构建 python27.dll 来跟踪一些致命错误,所以我对 python27.dll 的 2 个副本感到困惑
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-22
  • 2012-11-13
  • 2022-06-24
  • 2016-04-06
  • 2017-08-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多