8

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?

3
  • A little research wouldn't hurt: stackoverflow.com/questions/11436484/… Commented Apr 12, 2014 at 22:40
  • @FilipeGonçalves probably due to low views both of those questions didn't appear in my Googling. Commented Apr 12, 2014 at 22:44
  • Probably searching with the right term might be a bit of issue in this case. Google gives much better results if right terms are known Commented Apr 13, 2014 at 0:12

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

4 Comments

Could you answer a related question stackoverflow.com/questions/50459248/…
sure - getting page not found for the link??
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).
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.