简体   繁体   English

软件包中的Python C扩展-不起作用?

[英]Python C Extension in package - not working?

I'm working on packaging my python C extension and I'm running into trouble here: 我正在包装python C扩展程序,在这里遇到麻烦:

.
|-- c_ext/
|   |-- __init__.py
|-- c_src/
setup.py

With this setup.py 有了这个setup.py

from distutils.core import setup, Extension

setup( name = "Utilities",
       version = '1.0',
       description = ('Various utils'),
       packages = ["utils"],
       ext_modules = [Extension("utils.c_ext", ['c_src/c_extmodule.c'])]
       )

I can build without problems but after installing I can't import my module, I just get an ImportError. 我可以毫无问题地进行构建,但是安装后无法导入模块,我只会收到ImportError。

I'm sure it's something trivial, so what am I missing? 我确定这是一件微不足道的事情,那么我想念的是什么?

Thanks in Advance! 提前致谢!

Do you have a function in your module with the following signature: 您的模块中是否具有以下签名的功能:

PyMODINIT_FUNC initc_ext(void);

When you import a C extension it calls the function init where is the exact name of the extension. 导入C扩展名时,它将调用函数init,其中是扩展名的确切名称。 (Note that the convention is for C extensions to be named something like _foo and you get a function like init_foo) (请注意,约定是将C扩展名命名为_foo之类,并且您会获得init_foo之类的函数)

The exact error would also help diagnose this better. 确切的错误也将有助于更好地进行诊断。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM