1

I have a python code that uses various libraries like numpy, scipy etc.. Now due to some reasons, in my program I can use only c/c++. How can I convert this python code to c/c++? I thought of converting everything manually, but I don't know what I should do about the libraries that are being implemented.

Please help.

Sriram Bandaru
  • 55
  • 1
  • 1
  • 7
  • 2
    Can you "freeze" your Python? https://wiki.python.org/moin/Freeze – Joe Z Dec 12 '13 at 05:25
  • There is no sensible way of "translating" your Python application which is a **High Level Language** along with any dependent 3rd-party libraries into C++ which is a **Lower Level Language**. – James Mills Dec 12 '13 at 05:32
  • 1
    You'll have to translate them manually, and try searching for similar libraries. – aIKid Dec 12 '13 at 05:33
  • 1
    `Now due to some reasons` .. may be if you amplify on the reasons, possible solutions may be sought out? – Abhijit Dec 12 '13 at 06:06
  • something like this: http://docs.scipy.org/doc/numpy/reference/c-api.html – zinking Dec 12 '13 at 06:16
  • Abhijit: I'm trying to develop an android application that uses both python and c++ codes. I couldn't use both sl4a and android-ndk keeping performance and speed in mind. So, I thought of converting everything into c++ and use android-ndk. – Sriram Bandaru Dec 12 '13 at 06:30
  • Possible duplicate of [Convert Python program to C/C++ code?](https://stackoverflow.com/q/4650243/608639) – jww Nov 21 '19 at 13:29

1 Answers1

13

Some of your choices are:

  1. Do it by hand and convert to other libraries - long job with lots of potential problems.
  2. Embed python in a C++ shell but leave a lot of it python.
  3. Use nuitka to convert and compile - you should still leave your code as python for maintenance in this case.
  4. Use cython.
  5. Use cx-freeze, pyinstaller or py2exe to convert your python into an exe if you are on windows.
  6. Treat your python code as a prototype and start from scratch.
Steve Barnes
  • 27,618
  • 6
  • 63
  • 73