Not sure if this is a PyBind11 problem per se, but it's one that I've encountered twice on this project, in the context of PyBind11.
I think I've solved it, but I couldn't find any other posts about the issue, so let this stand as possibly useful for future users.
My stack is a bit opaque, so I can't really explain what might have caused the problem.
For a project I'm working on, which builds using PyBind11 as an option, I encountered the following problem:
pybind11/include/pybind11/detail/common.h:112:10: fatal error: Python.h: No such file or directory
#include <Python.h>
^~~~~~~~~~
I fixed it then, but I'm not sure how. Later, when moving the project to another machine, I encountered the issue again.
After a while of trying to pinpoint it, I found that ensuring the python3-dev apt package was installed got rid of the issue. It's possible that switching pybind11 branch helped too.
similar issue.
Same issue here when I tried the example, and I want to use pybind11 with python2.7.
g++ -O3 -Wall -shared -std=c++11 -fPIC python -m pybind11 --includes example.cpp -o examplepython-config --extension-suffix
It can work with python3, I wonder how should I use it with python2.7 ?
Thanks
I suspect on my side of things it might be a virtual environment issue, but I can never reproduce it, or fix it in a consistent way.
@i-chaochen, I've been using CMake, and setting the Python version using the flag -DPYBIND11_PYTHON_VERSION=3.5.
I haven't built systems with PyBind11 using standard build commands, so perhaps someone else can illuminate. What would happen if you replace the call to python in the command with python2.7?
I suspect on my side of things it might be a virtual environment issue, but I can never reproduce it, or fix it in a consistent way.
@i-chaochen, I've been using CMake, and setting the Python version using the flag
-DPYBIND11_PYTHON_VERSION=3.5.I haven't built systems with PyBind11 using standard build commands, so perhaps someone else can illuminate. What would happen if you replace the call to
pythonin the command withpython2.7?
Thanks, I just tried it and it's the same, my default python is python2.7.15rc1.
same problem, any fix available?
centos7 yum install python-devel
what about windows?
Haven't tried on Windows, what is your setup like?
My heuristic when this has come up again for me has been:
Solved on my CentOS 7.7 via yum install python36-devel. Check if there's a similar python or python3 dev or devel package you can install to resolve.
I wander how to solve this problem under macOS :D
I'm on macOS 10.15, so I can give some hints.
-I/some/path/to/python/include/dirOn macOS I would recommend installing latest Python3 via homebrew.
No matter how you install your Python or whether you use the system Python, you should have it on path and be able to consult python3-config to give you some answers to above questions.
Specifically:
python3-config --prefixpython3-config --includepython3-config -ldflagsI am trying to use pybind11 on a cluster. I have loaded module python/3.6-anaconda-5.2 and I am encountering this error. Could someone please help me with a solution for this?
Thanks, @darwin & @edrozenberg & @wangdxh for answering!
See also the answer in #1781.
Most helpful comment
I'm on macOS 10.15, so I can give some hints.
-I/some/path/to/python/include/dirOn macOS I would recommend installing latest Python3 via homebrew.
No matter how you install your Python or whether you use the system Python, you should have it on path and be able to consult
python3-configto give you some answers to above questions.Specifically:
python3-config --prefixpython3-config --includepython3-config -ldflags