I am starting out with pybind11
, trying to compile the first example. I am using Xubuntu 20.04. My system python is 3.8, but I have install pybind11
only for python 3.10, which is the version that executes when I type python
at the command prompt. When I run the compilation command given in the pybind11
docs:
c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3.10 -m pybind11 --includes) example.cpp -o example$(python3.10-config --extension-suffix)
I get the error message:
fatal error: Python.h: No such file or directory
213 | #include <Python.h>
I followed the advice give in the accepted answer to fatal error: Python.h: No such file or directory, and ran
sudo apt install python3.10-dev
but this had no effect, even though Python.h
now exists in /usr/include/python3.10
.
I should perhaps mention that I am not using a virtual environment at this point.
EDIT
python3.10-config --cflags
-I/usr/include/python3.10 -I/usr/include/python3.10 -Wno-unused-result -Wsign-compare -g -fstack-protector-strong -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O2 -Wall
EDIT
I changed the command as suggested by 9769953:
Pybind11Test$ c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3.10 -m pybind11 python3.10-config --includes) example.cpp -o example$(python3.10-config --extension-suffix)
usage: __main__.py [-h] [--includes] [--cmakedir]
__main__.py: error: unrecognized arguments: python3.10-config
example.cpp:1:10: fatal error: pybind11/pybind11.h: No such file or directory
1 | #include <pybind11/pybind11.h>
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Adding python3.10-config
gave me an unrecognized argumnents
error, but the compilation failed at a different place. #include <pybind11/pybind11.h>
is the first line of example.cpp
.
The file exists at
/home/saul/.local/lib/python3.10/site-packages/pybind11/include/pybind11/pybind11.h
EDIT
Latest attempt
Pybind11Test$ c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3.10 -m pybind11 --includes) example.cpp -o example.out
In file included from /home/saul/.local/lib/python3.10/site-packages/pybind11/include/pybind11/detail/../cast.h:13,
from /home/saul/.local/lib/python3.10/site-packages/pybind11/include/pybind11/detail/../attr.h:13,
from /home/saul/.local/lib/python3.10/site-packages/pybind11/include/pybind11/detail/class.h:12,
from /home/saul/.local/lib/python3.10/site-packages/pybind11/include/pybind11/pybind11.h:13,
from example.cpp:1:
/home/saul/.local/lib/python3.10/site-packages/pybind11/include/pybind11/detail/../detail/common.h:213:10: fatal error: Python.h: No such file or directory
213 | #include <Python.h>
| ^~~~~~~~~~
compilation terminated.