lava / matplotlib-cpp

Extremely simple yet powerful header-only C++ plotting library built on the popular matplotlib
MIT License
4.28k stars 1.12k forks source link

Cannot open include file: 'Python.h' #282

Open flaviu22 opened 2 years ago

flaviu22 commented 2 years ago

I am trying to use this header only library. And I get it down from github, and I put it into a folder. And in a test VS2017 C++ console project (in Windows 10), with a simple line:

#include "..\matplotlib-cpp\matplotlibcpp.h"

I've generated a nice error:

1>c:\project\matplotlib-cpp\matplotlibcpp.h(5): fatal error C1083: Cannot open include file: 'Python.h': No such file or directory Yes, I know I should use libpython library (I guess), but until there I need to overcome this error: Cannot open include file: 'Python.h'

I have installed Python 3.9:

C:\Project>python --version
Python 3.9.6

Also, I already have installed matplotlib in Python: matplotlib 3.4.2

Can you lead me to solve this ? Thank you for any hint !!!

P.S. I have included in my test project the requested path: C:\Program Files\Python39\include But now I got another missing files, which make me to think that I am not going in the right direction to solve this. How can I use this library in Visual Studio on Windows ?

P.S2. I have installed on my system matplotlib-cpp using vcpkg:

image

Even so, I still have the same error in my test app.

flaviu22 commented 2 years ago

No idea how can I use it in Windows ?

msevnctkn commented 2 years ago

No idea how can I use it in Windows ?

have you solved this problem? Now, I am facing 'Python.h': No such file or directory error.

Kin-Zhang commented 2 years ago

I have this problem on ubuntu when I catkin_make But if I just debug for that the spefic file you can add on task.json with arg: g++ minimal.cpp -std=c++11 -I/usr/include/python2.7 -lpython2.7

Like this one task.json:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-I/usr/include/python2.7",
                "-lpython2.7"
            ],
            "options": {
                "cwd": "${fileDirname}"

            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

I also still struggling about python.h when I catkin_make workspace.

OK, I think I found out the way: https://stackoverflow.com/questions/11041299/python-h-no-such-file-or-directory In your CMakeLists.txt, try adding the following:

find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(<your exe or lib> ${PYTHON_LIBRARIES})
msevnctkn commented 2 years ago

the problem is that location of your 'Python.h' is not match with the library's 'Python.h' file.

arunumd commented 2 years ago

I had the same problem. My problem was caused by not calling _target_linklibraries in CMakeLists.txt

The problem got solved by adding this

target_link_libraries(project_name
        PRIVATE
        ${PYTHON_LIBRARIES}
        Python3::NumPy
        )