1

I want to write code in Python but still have real-time capable code. This means I cannot use the Python interpreter. Mypyc looks promising for this very specific purpose, even though it is not a goal of the tool, as it is only meant to accelerate Python. Would it be possible to run mypyc generated code without the Python interpreter?

I have tried the following things, without success:

  • Compiling __native.c with gcc and manually linking it to files it requires, such as Python.h (in python installation) and mypyc libraries.
  • Opening the .so file in a C program with dlopen and importing functions with dlsym.
Hidde
  • 11
  • 1
  • 1
    Did 'mypyc' create a C-source? How did you try to compile it, and what error-message did you get? – Lorinczy Zsigmond Sep 22 '21 at 11:31
  • mypyc's main output is a .so file, but in the build directory a file named `__native.c` can be found. This file is difficult to read and has a lot of dependencies which can be found in two places: the first is `Python.h` which is part of CPython and can be found in `/usr/include/python3.9`, the others are libraries from mypyc itself and can be found in the site-packages directory, in my case `/home//.local/lib/python3.9/site-packages/mypyc/lib-rt/`. I linked these two directories with `-I`. This results in a lots of `undefined reference to ...`, for instance `PyList_Append`. – Hidde Sep 23 '21 at 12:27

0 Answers0