Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to put my Python C-module inside package?
    primarykey
    data
    text
    <p>I would like to gather multiple Python modules under one package, so they do not reserve too many names from global set of python packages and modules. But I have problems with modules that are written in C.</p> <p>Here is a very simple example, straight from the official Python documentation. You can find it at the bottom of the page from here: <a href="http://docs.python.org/distutils/examples.html" rel="nofollow">http://docs.python.org/distutils/examples.html</a></p> <pre><code>from distutils.core import setup from distutils.extension import Extension setup(name='foobar', version='1.0', ext_modules=[Extension('foopkg.foo', ['foo.c'])], ) </code></pre> <p>My foo.c file looks like this</p> <pre><code>#include &lt;Python.h&gt; static PyObject * foo_bar(PyObject *self, PyObject *args); static PyMethodDef FooMethods[] = { { "bar", foo_bar, METH_VARARGS, "" }, {NULL, NULL, 0, NULL} }; static PyObject * foo_bar(PyObject *self, PyObject *args) { return Py_BuildValue("s", "foobar"); } PyMODINIT_FUNC initfoo(void) { (void)Py_InitModule("foo", FooMethods); } int main(int argc, char *argv[]) { // Pass argv[0] to the Python interpreter Py_SetProgramName(argv[0]); // Initialize the Python interpreter. Required. Py_Initialize(); // Add a static module initfoo(); return 0; } </code></pre> <p>It builds and installs fine, but I cannot import foopkg.foo! If I rename it to just "foo" it works perfectly.</p> <p>Any ideas how I can make the "foopkg.foo" work? For example changing "foo" from Py_InitModule() in C code to "foopkg.foo" does not help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload