Python.h not found
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:
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
Try -I$PREFIX/include/python3.12.
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.
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 '
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.
there are no quotes, i copypasta'd what you sent
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
Thank you, this seems to have worked