How to import python module from .so file? How to import python module from .so file? python python

How to import python module from .so file?


take that 'hello_world.so' file and and make new python file (in the same dir) named as 'hello_world.py'.Put the below code in it.. .

def __bootstrap__():   global __bootstrap__, __loader__, __file__   import sys, pkg_resources, imp   __file__ = pkg_resources.resource_filename(__name__,'hello_world.so')   __loader__ = None; del __bootstrap__, __loader__   imp.load_dynamic(__name__,__file__)__bootstrap__()

now you can import this hello_world as:

>>> import hello_world


It must be called hello_world.so, not libhello_world.so.