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?
Asked
Active
Viewed 2.3k times
8
-
A little research wouldn't hurt: http://stackoverflow.com/questions/11436484/how-to-protect-and-compile-python-source-code-into-a-so-library – Filipe Gonçalves Apr 12 '14 at 22:40
-
@FilipeGonçalves probably due to low views both of those questions didn't appear in my Googling. – Mauren Apr 12 '14 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 – fkl Apr 13 '14 at 00:12
1 Answers
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"
-
Could you answer a related question https://stackoverflow.com/questions/50459248/linux-how-to-simulate-environment-is-which-python-is-not-installed – user13107 May 22 '18 at 03:17
-
-
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). – ilias iliadis Oct 06 '19 at 04:38
-
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 – fkl Oct 07 '19 at 09:18