Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with running the first example #1781

Closed
sursu opened this issue May 4, 2019 · 3 comments
Closed

Issues with running the first example #1781

sursu opened this issue May 4, 2019 · 3 comments

Comments

@sursu
Copy link

sursu commented May 4, 2019

I have Ubuntu 18.04.
A few months ago I was able to use pybind11. In the meantime I have deleted some files and decided to do a clean installation.
I have cleared everything so that now when I run locate pybind11 I don't get anything.

I have tried to install pybind11 in 2 ways:

First:

Clone the repository:

git clone https://github.com/pybind/pybind11.git

Run:

mkdir build
cd build
cmake ..
make check -j 4

Then I have the main.cpp file.

#include <pybind11/pybind11.h>

int add(int i, int j) {
    return i + j;
}
namespace py = pybind11;
PYBIND11_PLUGIN(example) {
    py::module m("example", "pybind11 example plugin");
    m.def("add", &add, "A function which adds two numbers");
    return m.ptr();
}

and the CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)
project(example)

find_package(pybind11 REQUIRED)
pybind11_add_module(example main.cpp)

When the configuration of cmake takes place I get the following errors:

[cmake]   CMake Error at CMakeLists.txt:8 (find_package):
[cmake]   By not providing "Findpybind11.cmake" in CMAKE_MODULE_PATH this project has
[cmake]   asked CMake to find a package configuration file provided by "pybind11",
[cmake]   but CMake did not find one.
[cmake] 
[cmake]   Could not find a package configuration file provided by "pybind11" with any
[cmake]   of the following names:
[cmake] 
[cmake]     pybind11Config.cmake
[cmake]     pybind11-config.cmake
[cmake] 
[cmake]   Add the installation prefix of "pybind11" to CMAKE_PREFIX_PATH or set
[cmake]   "pybind11_DIR" to a directory containing one of the above files.  If
[cmake]   "pybind11" provides a separate development package or SDK, be sure it has
[cmake]   been installed.
[cmake] 
[cmake] 
[cmake] Configuring incomplete, errors occurred!

Second:

When I do the installation via conan, and run the program with the new CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)
project(example)

add_definitions("-std=c++11")

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(example main.cpp)
target_link_libraries(example ${CONAN_LIBS})

I get the following error:

In file included from /home/ursus/.conan/data/pybind11/2.2.4/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/pytypes.h:12:0,
                 from /home/ursus/.conan/data/pybind11/2.2.4/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/cast.h:13,
                 from /home/ursus/.conan/data/pybind11/2.2.4/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/attr.h:13,
                 from /home/ursus/.conan/data/pybind11/2.2.4/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/pybind11.h:43,
                 from /home/ursus/Documents/CORE/Quelle/Python/Pybind11/example/main.cpp:1:
/home/ursus/.conan/data/pybind11/2.2.4/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/detail/common.h:112:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.

it is very much the same issue as #1728.

@YannickJadoul
Copy link
Collaborator

First:

Clone the repository:

git clone https://github.com/pybind/pybind11.git

Run:

mkdir build
cd build
cmake ..
make check -j 4

You didn't install it. You only built the tests and ran them in that local directory, so obviously, CMake can't just randomly guess there it needs to look. make install for find_package(pybind11 REQUIRED) to work (or set CMAKE_MODULE_PATH or CMAKE_PREFIX_PATH or pybind11_DIR, as the CMake error helpfully suggests!), or add_subdirectory(foo/bar/pybind11) to not use a global installation.

Second:

When I do the installation via conan, and run the program with the new CMakeLists.txt:

[...]

I get the following error:

In file included from /home/ursus/.conan/data/pybind11/2.2.4/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/pytypes.h:12:0,
                 from /home/ursus/.conan/data/pybind11/2.2.4/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/cast.h:13,
                 from /home/ursus/.conan/data/pybind11/2.2.4/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/attr.h:13,
                 from /home/ursus/.conan/data/pybind11/2.2.4/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/pybind11.h:43,
                 from /home/ursus/Documents/CORE/Quelle/Python/Pybind11/example/main.cpp:1:
/home/ursus/.conan/data/pybind11/2.2.4/conan/stable/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/pybind11/detail/common.h:112:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.

You need to install the Python headers. On Ubuntu, you can install the python-dev (or python3-dev or pythonX.Y-dev) package.

@santiagodemierre
Copy link

Installing the specific python3.7-dev solved the problem, I had 3.6 and 3.8 but not 3.7
Thanks for your help

@lc8631058
Copy link

My case: using Amazon EC2 Ubuntu 20.04.5 LTS, installed python3-dev, python-dev, python3.8-dev using apt, none of those can solve the "Python.h no such file" problem. Finally found a solution in here and it works for me: Python.h: no such file or directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants