我正在用 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 文件,该文件适用于我的计算机。
最佳答案
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/