为什么打不开python.pyd文件,在pyd中导入python文件时导入ErrorError

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__

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

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

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.

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?

解决方案

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

You should try to import the pyd first:

import apple

Then you can (probably) access the internal API:

WM = apple.seed.worm.WormManager

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 ....

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值