python - Cython pyd文件不通过python导入

标签 python python-3.x cython python-import

我正在用 python 编写一个程序来模拟粒子的 react ,目的是教用户了解粒子 react 。由于 python 在进行必要的处理时速度太慢,我转向 Cython 以提高速度,它起到了很好的作用。我可以编译我的 .pyx文件变成 .pyd可以使用简单的 import 从 python 导入和运行的文件语句(即“导入模块”)。

但是,该程序最终必须在另一个人的计算机上运行,​​而在这台计算机上,.pyd文件不会导入。当我尝试时,我收到此错误消息:

"ImportError: DLL load failed: The specified module could not be found."
.pyd文件在两台计算机上的位置完全相同,但是,我正在运行 python 3.6,而另一台计算机安装了 python 3.3。另外,我的电脑安装了 Cython,而另一台电脑没有。两台机器都是32位的。

我不能简单地将整个程序编译成 .exe文件,因为另一台计算机在 .exe 上有一个块文件。

我已经浏览了关于 Cython 的堆栈问题,并且还研究了 Cython 文档,但都无济于事。

有人可以向我解释为什么导入不起作用,以及如何让它起作用?关于确切内容的一些额外背景.pyd文件以及 python 调用它们的方式也很好。

编辑:我从名为 main.py 的文件运行程序。在同一个目录中,我有一个名为 main 的文件夹,它存储我在模块中使用的代码。 main.py 调用 PageManager.py,后者调用 ParticleModel.py,后者调用 MoveParticles.pyd。
(这三个文件存放在文件夹main中)。我使用语句
"import main.MoveParticles" 

导入 .pyd 文件,该文件适用于我的计算机。

最佳答案

根据 https://cython-devel.python.narkive.com/gqx0VU3L/importerror-dll-load-failed-the-specified-module-could-not-be-found

Just interpreting the error you're describing (ImportError: DLL load failed: could not be found), the dynamic linker couldn't find a library it needed. Most likely this is either a symptom of missing dependencies or a path problem. Here's my suggestions for diagnosing and fixing the problem:

Missing Dependencies: One very simple way to confirm that all the dependencies of your cython module are available is to point the dependency walker utility[1] at it, and look for missing DLLs.

Directory Structure: Is the .pyd file you built from your cython module in the PYTHONPATH (or your current working directory? If it's not, there's your issue.


如果缺少依赖项,请在此处下载依赖项walker:http://www.dependencywalker.com/ .然后打开您的 .pyd 文件并稍等片刻。查看主分支中是否缺少文件,并将这些文件添加到包含 python38.dll 的目录中(我的情况是:C:\Users\PC\AppData\Local\Programs\Python\Python38)。

关于python - Cython pyd文件不通过python导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46392003/

相关文章:

Python pandas : Multi-column filter using ~df. type.isin 和 !=

python - Keras my_layer.output 返回 KerasTensor 对象而不是 Tensor 对象(在自定义损失函数中)

python - pandas 表达式中带有格式修饰符的 F 字符串会触发 Series.__format__ 中的 TypeError

python - TypeError : expected str, 字节或 os.PathLike 对象,而不是 _io.TextIOWrapper

python - Selenium 错误 : AttributeError: 'Service' object has no attribute 'process'

python-3.x - 如何在python的类中使用光线并行性?

python - 在解释器中运行 Cython 代码

python - Cython cdef 类不显示文档字符串或 __init__ 参数

python - 如何解决Python中的azure keyvault secret (未经授权)AKV10032 : Invalid issuer.错误

python - GCC 未编译 Cython 扩展