本文介绍了在pyd中导入python文件时导入ErrorError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我正在尝试做的是在.pyd文件中打包的文件夹中导入模块。这对我有用:

Alright, so, what I'm trying to do is import a module in folders packed inside of a .pyd file. Here is something that would work for me:

from apple import __init__

苹果是与Python脚本在同一目录中的.pyd,而__init__当然是在.pyd内部打包的。这可行,但这是我想做的,但不起作用:

With apple being the .pyd in the same directory as the Python script, and __init__ of course being packed inside of the .pyd. This would work, however here is what I want to do, but doesn't work:

from apple.seed.worm import WormManager

说明:apple = pyd,seed = pyd中的目录,worm =种子目录中的目录蠕虫目录中的apple pyd,WormManager = python模块。

Explanation: apple = pyd, seed = directory in the pyd, worm = directory in seed directory in apple pyd, WormManager = python module in the worm directory.

然而,它不起作用,导致找不到模块的ImportError认为种子是一个模块(和在打包之前,种子目录中有一个__init__。当然它存在并包装在.pyd中,但它根本不起作用。我甚至这样做了:

However, it does not work, and results in a module not found ImportError thinking that seed is a module (and there was an __init__ inside of the seed directory before it was packed). Of course it exists and is packed in the .pyd, but it simply does not work. I even did this:

from apple.seed import __init__

但即使这样也行不通,所以我知道我没有输入这个权利。

but not even that works so I know that I'm not importing this right.

我真的不能找到使其在互联网上运行的正确语法,当然我知道如何在没有涉及pyd的情况下执行此操作,那么任何帮助?

I really could not find the correct syntax for getting this to work on the internet, and of course I know how to do this without a pyd involved, so any help?

推荐答案

我不确定,但我认为Python无法动态发现内部pyd API而不先导入它。

I'm not sure but I think that Python cannot dynamically discover internal pyd API without importing it first.

你应该先尝试导入pyd :

You should try to import the pyd first:

import apple

然后你可以(可能)访问内部API:

Then you can (probably) access the internal API:

WM = apple.seed.worm.WormManager

此外,您的 apple.pyd dll文件每个。如果它没有,或者它是不明确的(没有定义所有子模块),这可以解释为什么你不能从apple ... 。

Also, your apple.pyd dll file must contain a function PyInit_apple() per the official documentation. If it doesn't, or if it is ill-defined (doesn't define all the submodules), this may explain why you cannot do from apple ....

这篇关于在pyd中导入python文件时导入ErrorError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-20 06:15