Create dynamic library (.so file) from Python code

16,774

This should help.

Also you can do both ways i.e. extend python by writing library in C and call it from Python code OR code functions in C that could be called from Python.

The standard term used (conceptually and help googling is "Python bindings"

Official reference from python docs

General reference - Integrating python with other languages

Share:
16,774
Mauren
Author by

Mauren

Experienced software engineer, with a strong background in Java development.

Updated on June 15, 2022

Comments

  • Mauren
    Mauren almost 2 years

    Suppose I have a library written in Python that I'd like to call from a C software. Is there any way I can compile this Python code to a .so file?

  • user13107
    user13107 almost 6 years
    Could you answer a related question stackoverflow.com/questions/50459248/…
  • fkl
    fkl almost 6 years
    sure - getting page not found for the link??
  • ilias iliadis
    ilias iliadis over 4 years
    The question is very-very clear. I am not sure why this shows up as an answer at all. The first (assumed as the main) link starts with «There are several ways to call code written in C from Python» which is the exact opposite of the, included in the question, «I'd like to call from a C software». The rest is about «doing it both ways»!? (probably for some other question).
  • fkl
    fkl over 4 years
    Whether one needs to call python to c or c to python, the requirement is to understand how "python bindings work" which is the first reference and which is why it latter talks about doing it either way. The next link "Official reference .." is indeed "Calling Python functions from C". Hope that helps