Hi,
Valerron White schrieb am 20.12.21 um 12:20:
> I am on Ubuntu. I have the one problem for all files, it is the line
> #include "Python.h"
> It gives error by all compilers. I have already read that this line can be
> edited manually.
> Is it normal to edit generated file manually?
No.
> Maybe I missed some options...
> Please help.
>
> The file content is not important. Let it be a file from example.
>
> A.py
>
> def myfunction(x, y=2):
> a = x - y
> return a + x * y
>
> def _helper(a):
> return a + 1
>
> class A:
> def __init__(self, b=0):
> self.a = 3
> self.b = b
>
> def foo(self, x):
> print(x + _helper(1.0))
>
>
> I generate the file with the line:
> cython --embed -o A.cpp A.py
Cython's embedding mode isn't exactly made for beginners. It's a rather
special purpose thing that helps some people. Most users should use
extension modules instead.
If you really want to build a stand-alone executable, take a look at the
embedding example here:
https://github.com/cython/cython/tree/master/Demos/embed
> After that I compile the file with the line:
> clang++-12 -pthread -std=c++17 -o main A.cpp
>
> The error is:
> A.cpp:6:10: fatal error: 'Python.h' file not found
> #include "Python.h"
> ^~~~~~~~~~
> 1 error generated.
>
> The compiler is not important, I have the same problem with gcc and g++.
There should be an additional error line that tells you to install the
Python dev package. On Ubuntu, it is called "python3-dev".
You also need to pass the Python include directory with -I, link against
lib Python, etc. The example above has all that. It's a bunch of options to
provide to the C/C++ compiler.
Stefan