matplotlib-cpp icon indicating copy to clipboard operation
matplotlib-cpp copied to clipboard

Cannot open include file: 'Python.h'

Open flaviu22 opened this issue 3 years ago • 5 comments

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 avatar Sep 08 '21 09:09 flaviu22

No idea how can I use it in Windows ?

flaviu22 avatar Sep 13 '21 07:09 flaviu22

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.

msevnctkn avatar Oct 10 '21 16:10 msevnctkn

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})

Kin-Zhang avatar Nov 08 '21 07:11 Kin-Zhang

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

msevnctkn avatar Nov 08 '21 17:11 msevnctkn

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

The problem got solved by adding this

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

arunumd avatar Mar 25 '22 05:03 arunumd