A more reliable way to get this flag is to use pkg-config
. For instance:
$ pkg - config--cflags python - I / usr / include / python2 .7 - I / usr / include / x86_64 - linux - gnu / python2 .7 $ pkg - config--cflags python3 - I / usr / include / python3 .6 m - I / usr / include / x86_64 - linux - gnu / python3 .6 m
Try installing the package libpython3.8-dev, that should put the Python.h file into /usr/include/python3.8/Python.h Use apt-file search Python.h to find the packages that contain it. After installing apt-file, you will need to run apt-fil update to let it update its database.,I just switched to Linux (Ubuntu 20.04) from Windows. After installing python-dev I notice that Python.h is still not included, which breaks my integrated Python-C++ build (I'm using pybind11). I also tried to install every other variant of python-dev I saw mentioned online (python3-dev, python-devel, etc.) but to no avail., How are "long push buttons" done? (For example, a "factory reset button" that has to be pushed for five seconds.) ,Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
You can try the following:
sudo updatedb locate Python.h
Output:
/usr/include / python2 .7 / Python.h / usr / include / python3 .5 m / Python.h
Then set
export CPATH = /usr/include / python3 .5 m: $CPATH
export LD_LIBRARY_PATH = /usr/lib: $LD_LIBRARY_PATH
Which $path is needed so g++/pybind11 could locate Python.h? ,Which $path is needed so g++/pybind11 could locate Python.h?,To test the waters, I created a do-nothing wrapper around my c++ library. Alas, the compilation is unable to find Python.h:,Which (path?) should I correct so g++ would be able to locate Python.h?
pip install git + https: //github.com/pentschev/pybench
pytest pybench / benchmarks /*
$ pkg - config--cflags python - I / usr / include / python2 .7 - I / usr / include / x86_64 - linux - gnu / python2 .7 $ pkg - config--cflags python3 - I / usr / include / python3 .6 m - I / usr / include / x86_64 - linux - gnu / python3 .6 m
$ g++ -std=c++0x -fPIC -pedantic -g -Wno-missing-field-initializers -Wno-switch -Wno-multichar -ftree-vectorize -ftree-vectorize -mssse3 backend.h uvc-v4l2.cpp wrap.cpp -o wrap.so
backend.h:4:9: warning: #pragma once in main file
#pragma once
^
In file included from /usr/local/include/pybind11/pytypes.h:12:0,
from /usr/local/include/pybind11/cast.h:13,
from /usr/local/include/pybind11/attr.h:13,
from /usr/local/include/pybind11/pybind11.h:36,
from wrap.cpp:1:
/usr/local/include/pybind11/common.h:72:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
$ find / usr - name Python.h / usr / include / python2 .7 / Python.h / usr / include / python3 .5 m / Python.h
$ apt list | grep - iE--'^python.-dev|^python-dev'
WARNING: apt does not have a stable CLI interface.Use with caution in scripts.
python - dev / xenial, now 2.7 .11 - 1 amd64[installed]
python3 - dev / xenial, now 3.5 .1 - 3 amd64[installed]
$ dpkg - S Python.h
libpython2 .7 - dev: amd64: /usr/include / python2 .7 / Python.h
libpython3 .5 - dev: amd64: /usr/include / python3 .5 m / Python.h
$ dpkg - L python2 .7 - dev /
. /
usr /
usr / bin /
usr / share /
usr / share / man /
usr / share / man / man1 /
usr / share / doc /
usr / share / doc / python2 .7 /
usr / share / doc / python2 .7 / x86_64 - linux - gnu /
usr / share / doc / python2 .7 / x86_64 - linux - gnu / test_results.gz /
usr / share / doc / python2 .7 / x86_64 - linux - gnu / pybench.log.gz /
usr / share / doc / python2 .7 / gdbinit.gz /
usr / share / doc / python2 .7 / HISTORY.gz /
usr / share / doc / python2 .7 / README.valgrind.gz /
usr / share / doc / python2 .7 / README.maintainers /
usr / bin / python2 .7 - config /
usr / share / man / man1 / python2 .7 - config .1.gz /
usr / share / doc / python2 .7 - dev
(Take a look at the compiler commands that are echoed to the terminal when setup.py is run.),distutils knows about SWIG, so instead of including example_wrap.c in the list of source files, you can include example.i, and swig will be run automatically by the setup script:,However, to build the extension module, I recommend using a simple setup script, such as the following setup.py, and let distutils figure out all the compiling and linking options for you.,If you'd rather not use the script setup.py, here's a set of commands that worked for me:
gcc - c example.c example_wrap.c - I / Users / myuser / anaconda / include /
$ python - config--cflags - I / Users / myuser / anaconda / include / python2 .7 - I / Users / myuser / anaconda / include / python2 .7 - fno - strict - aliasing - I / Users / myuser / anaconda / include - arch x86_64 - DNDEBUG - g - fwrapv - O3 - Wall - Wstrict - prototypes
gcc - c example.c example_wrap.c - I / Users / myuser / anaconda / include /
example_wrap.c:130:11: fatal error: 'Python.h' file not found # include <Python.h> ^
$ python - config--cflags - I / Users / myuser / anaconda / include / python2 .7 - I / Users / myuser / anaconda / include / python2 .7 - fno - strict - aliasing - I / Users / myuser / anaconda / include - arch x86_64 - DNDEBUG - g - fwrapv - O3 - Wall - Wstrict - prototypes
# setup.py from distutils.core import setup, Extension example_module = Extension('_example', sources = ['example_wrap.c', 'example.c']) setup(name = 'example', ext_modules = [example_module], py_modules = ["example"])