Many well-known python libraries are basically written in C (like tensorflow or numpy) because this apparently speeds things up a lot. I was able to very easily integrate a C function into python by reading this.
Doing so I can finally use distutils
to access the functions of the source.c
file:
# setup.py
from distutils.core import setup, Extension
def main():
setup(
# All the other parameters...
ext_modules=[ Extension("source", ["source.c"]) ]
)
if __name__ == "__main__":
main()
so that when i run python setup.py install
i can install my library.
However, what if i want to create a python-coded wrapper object for the functions inside source.c
? Is there a way to do this without polluting the installed modules?
Wandering around the internet I have seen some seemingly simple solutions using shared libraries (.so
). However I would need a solution that does not involve attaching the compiled C code, but one that compiles it the first time the program is run.