Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python.h not found #4274

Closed
yeetssite opened this issue Nov 25, 2024 · 7 comments
Closed

Python.h not found #4274

yeetssite opened this issue Nov 25, 2024 · 7 comments

Comments

@yeetssite
Copy link

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
@twaik
Copy link
Member

twaik commented Nov 25, 2024

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

@trygveaa
Copy link
Contributor

trygveaa commented Nov 25, 2024

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.

@yeetssite
Copy link
Author

yeetssite commented Nov 25, 2024

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 '

@trygveaa
Copy link
Contributor

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.

@yeetssite
Copy link
Author

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

@trygveaa
Copy link
Contributor

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

@yeetssite
Copy link
Author

Thank you, this seems to have worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants