termux-app icon indicating copy to clipboard operation
termux-app copied to clipboard

Python.h not found

Open yeetssite opened this issue 1 year ago • 4 comments

Problem description

I generated a C file from Python 3.12 using Cython:

$ cython --embed -o tets.c test.py

I ran GCC with these flags:

$ gcc $(python-config --cflags) tets.c $(python-config --libs)

But I keep getting the error:

tets.c:16:10: fatal error: 'Python.h' file not found
   16 | #include "Python.h"
      |          ^~~~~~~~~~
1 error generated.

Here is an image:

Screenshot_20241125-134130_Termux

Steps to reproduce the behavior.

Generate an embedded python C file with cython:

$ cython --embed -o tets.c test.py

Run GCC with, from my understanding, the appropriate flags:

$ gcc $(python-config --cflags) tets.c $(python-config --libs)

What is the expected behavior?

The file tets.c compiles into an executable binary file.

System information

  • Termux application version: 0.118.1 (according to app info(
  • Android OS version: 10
  • Device model: Samsung galaxy S9

yeetssite avatar Nov 25 '24 20:11 yeetssite

Try -I$PREFIX/include/python3.12.

twaik avatar Nov 25 '24 20:11 twaik

Run GCC with, from my understanding, the appropriate flags:

$ gcc $(python-config --cflags) tets.c $(python-config --libs)

This isn't exactly correct. What you want is this

gcc $(python-config --cflags) tets.c $(python-config --ldflags --embed)

Though, when I read it again I realized that since you get 'Python.h' file not found, this is likely not your issue.

trygveaa avatar Nov 25 '24 21:11 trygveaa

yeah, tried it again, now it spits out

gcc: error: no such file or directory: ' -L/data/data/com.termux/files/usr/lib -lpython3.12 -ldl  -lpthread -lm '

yeetssite avatar Nov 25 '24 23:11 yeetssite

If you get that error you've likely put quotes around the second $(python-config ...). You should not do that.

And I see now that putting quotes around the first $(python-config ...) will produce the error you had initially. Make sure not to include any quotes anywhere, use exactly the command I posted.

trygveaa avatar Nov 26 '24 00:11 trygveaa

there are no quotes, i copypasta'd what you sent

yeetssite avatar Nov 26 '24 05:11 yeetssite

Try running the python-config commands separately and insert them into the gcc command manually.

On my phone python-config --cflags prints -I/data/data/com.termux/files/usr/include/python3.12 -I/data/data/com.termux/files/usr/include/python3.12 -fno-strict-overflow -Wsign-compare -Wunreachable-code -fstack-protector-strong -O3 -DNDEBUG -g -O3 -Wall.

And python-config --ldflags --embed prints -L/data/data/com.termux/files/usr/lib -lpython3.12 -ldl -lpthread -lm.

So that ends up being:

gcc -I/data/data/com.termux/files/usr/include/python3.12 -I/data/data/com.termux/files/usr/include/python3.12 -fno-strict-overflow -Wsign-compare -Wunreachable-code -fstack-protector-strong -O3 -DNDEBUG -g -O3 -Wall tets.c -L/data/data/com.termux/files/usr/lib -lpython3.12 -ldl -lpthread -lm

trygveaa avatar Nov 26 '24 19:11 trygveaa

Thank you, this seems to have worked

yeetssite avatar Nov 27 '24 02:11 yeetssite