0

I want to package my python project using this official tutorial

The problem is that my project uses a .so external library. When I make a package and import it in a random python script, i get this error:

ModuleNotFoundError: No module named 'myExternalLib'

I couldn't find any tutorial on how to add an external library to my package, I think I'm not searching with the right keywords.

Cydouzo
  • 445
  • 5
  • 18
  • 2
    The guide you linked only covers pure Python code. You will need to refer to the [Packaging binary extensions](https://packaging.python.org/guides/packaging-binary-extensions/) guide, and given that's an incomplete guide please refer to all the links. For a quick example on how this is done, refer to [this thread](https://stackoverflow.com/questions/48706842/python-3-x-c-extension-module-and-submodule). – metatoaster Nov 11 '20 at 03:17
  • Thank you for your pointers. I found a lot of great material for implementing C extension. But after exploring the guide and all the links that looked interesting, I honestly found nothing relevant to my issue. – Cydouzo Nov 11 '20 at 05:28
  • I am not trying to compile an extension. I have an extension that is already compiled, and I want to tell the setup file to add it to the package. – Cydouzo Nov 11 '20 at 05:29
  • 1
    You may try using [a `MANIFEST.in`](https://packaging.python.org/guides/using-manifest-in/) file to forcibly include the `*.so` files. This is not guaranteed to work as it isn't a portable solution, but if you don't care then this might address your requirements. – metatoaster Nov 11 '20 at 05:50
  • 1
    Do note that any other actually external `.so` library files that reside outside of your package (e.g. `/usr/lib/my_shared_lib.so`), there is no supported method to include them with a Python package file of any kind. – metatoaster Nov 11 '20 at 05:57
  • @metatoaster I found the solution that best fits my needs. Thanks a lot for your help and advice! – Cydouzo Nov 11 '20 at 08:23

1 Answers1

0

I think the easiest solution is to add the external library as a package data.

setup(
    ..... 
    packages=['myLib'],
    package_data={'myLib': ['myExternalLib.so']},
)
Cydouzo
  • 445
  • 5
  • 18