Which $path is needed so g++/pybind11 could locate Python.h?

Which $path is needed so g++/pybind11 could locate Python.h?



I started using pybind11 (on Ubuntu 16.04 with Python 2.7).


pybind11



To test the waters, I created a do-nothing wrapper around my c++ library. Alas, the compilation is unable to find Python.h:


Python.h


$ 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.



However, I do seem to have the file:


$ find /usr -name Python.h
/usr/include/python2.7/Python.h
/usr/include/python3.5m/Python.h



Which (path?) should I correct so g++ would be able to locate Python.h?


g++


Python.h






Notes:


$ 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.5m/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




1 Answer
1



-I/usr/include/python2.7


-I/usr/include/python2.7



The -I flag adds the directory to the list of directories to be searched for header files. If you were to instead want the python3.5 equivalent, you'd replace 2.7 with 3.5m


-I



A more reliable way to get this flag is to use pkg-config. For instance:


pkg-config


$ 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.6m -I/usr/include/x86_64-linux-gnu/python3.6m



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế