本文介绍了Cython编译的C扩展:ImportError:动态模块未定义init函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用Cython将我的C库的一部分编译为扩展,作为概念证明".我设法破解了代码(除了纠正常量等问题外),最终构建了扩展.

I have just compiled part of my C library as an extension using Cython, as a "proof of concept". I managed to hack the code (const correctnes problems etc aside), to finally get an extension built.

但是,当我尝试导入新创建的扩展名时,出现以下错误:

However, when I attempted to import the newly created extension, I got the following error:

ImportError: dynamic module does not define init function

我在做什么错了,我该如何解决?

What am I doing wrong and how do I fix this?

我正在Ubuntu 10.0.4上使用Cythn 0.11.2和Python 2.6.5

I am using Cythn 0.11.2 and Python 2.6.5 on Ubuntu 10.0.4

推荐答案

我发现此问题的常见原因是,使用distutils安装文件编译代码时,.pyx基本名称不匹配.扩展名,例如:

I've found that a frequent cause of this problem is, when using a distutils setup file to compile the code, that the .pyx base name does not match the extension name, e.g:

ext = Extension(name='different', sources=['cython_ext.pyx']) # Won't work

为避免此问题,扩展名应完全相同,在这种情况下为cython_ext.

To avoid the problem the extension name should be exactly the same, in this case, cython_ext.

这篇关于Cython编译的C扩展:ImportError:动态模块未定义init函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:44
查看更多