3

I have implemented a ctypes wrapper called api.c, and I have the structure:

lib/api.c
foo.py
setup.py

Compiling api.c manually and calling ctypes.CDLL(path+'lib/api.so') inside foo.py works, where path is the absolute pathname.

Now, I want distribute it with setup.py:

setup(name='foo',
      ext_modules=[Extension('lib.api', ['lib/api.c'])]
     )

Installing with python setup.py develop -u --user works, too, because api.so appears in lib/.

With python setup.py install --user the code is compiled, too, but api.so appears in some build/bdist.linux-x86_64/egg/lib folder. Therefore importing the module results in OSError: /.../lib/api.so: cannot open shared object file: No such file or directory

So how can I distribute it with install and what should be the value of path?

related issues: How to include a shared C library in a Python package

3

1 Answer 1

1

I found that when adding the argument py_modules=['foo'] to setup, python setup.py install installed it properly in the site-packages directory. Thus

setup(name='foo',
      py_modules=['foo'],
      ext_modules=[Extension('lib.api', ['lib/api.c'])]
     )
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.