11

I'm working in an embedded Linux environment and I have some Python code which I would like to use. My Python code is just doing some math, not using any library other than Numpy and the common ones.

Is there any way to build up a library that I can call from C or C++ code?

4
  • 4
    docs.python.org/extending/embedding.html may be of interest. Commented Feb 2, 2012 at 18:39
  • Also consider to actually make a C/C++ library to use in Python code (= extending as opposed to embedding). It's easy to overlook that this scenario can actually be more interesting for many applications Commented Feb 2, 2012 at 18:41
  • 1
    Check out Boost.Python! Commented Feb 2, 2012 at 18:41
  • 1
    Duplicate or at least interesting for you: stackoverflow.com/questions/4331599/… Commented Feb 2, 2012 at 18:45

1 Answer 1

15

Embedding the CPython interpreter into a C or C++ program is actually pretty straightforward.

The official documentation has some complete examples.

Also, check out SWIG and Boost.Python.

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

1 Comment

Cython may be worth to mention here, too. Even it's typically used the other way round.

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.