I have created a C library libgac
and then wrote Python module implementing bindings with ctype
.
I call the python module gazepy
.
My project file structure is as follows:
pyproject.toml
setup.py
src
gazepy
gac # repo with the C library libgac
gazepy.py # python bindings for the C library libgac
__init__.py # empty file
tests
Running sudo pip install .
generates and installs the so file gazepy.cpython-38-x86_64-linux-gnu.so
.
So far so good, however, if I want to import the library in a python3 shell I get the following error:
ImportError: dynamic module does not define module export function (PyInit_gazepy)
My pyproject.toml
file:
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
[project]
name = "gazepy"
# ...
My setup.py
file:
from setuptools import setup, Extension, find_packages
import subprocess
module_name = "gazepy"
module_path = "src/" + module_name
gac_path = module_path + "/gac"
cglm_path = gac_path + "/cglm"
def main():
setup(
name=module_name,
packages=find_packages(),
ext_modules=[
Extension(module_name, [gac_path + '/src/gac.c'],
include_dirs=[gac_path + '/include', cglm_path + '/include'],
libraries=['m'])
]
)
if __name__ == "__main__":
main()
When looking at the so file gazepy.cpython-38-x86_64-linux-gnu.so
I cannot find any definition of PyInit_gazepy()
:
nm /usr/local/lib/python3.8/dist-packages/gazepy.cpython-38-x86_64-linux-gnu.so | grep PyInit
What am I missing here?