Skip to content

Unable to compile examples on MacOS #361

Open
@ngquyduc

Description

@ngquyduc

fatal error: 'Python/Python.h' file not found

I tried to add the file to my current project to plot some graph but couldn't make it to work. Please help me in this matter.

There are 2 files matplotlibcpp.cpp and matplotlibcpp.h

I downloaded the matplotlibcpp.h file from this repo

Here is the example file matplotlibcpp.cpp

#include "matplotlibcpp.h"
#include <cmath>

namespace plt = matplotlibcpp;

int main()
{
    // Prepare data.
    int n = 5000;
    std::vector<double> x(n), y(n), z(n), w(n,2);
    for(int i=0; i<n; ++i) {
        x.at(i) = i*i;
        y.at(i) = sin(2*M_PI*i/360.0);
        z.at(i) = log(i);
    }

    // Set the size of output image to 1200x780 pixels
    plt::figure_size(1200, 780);
    // Plot line from given x and y data. Color is selected automatically.
    plt::plot(x, y);
    // Plot a red dashed line from given x and y data.
    plt::plot(x, w,"r--");
    // Plot a line whose name will show up as "log(x)" in the legend.
    plt::named_plot("log(x)", x, z);
    // Set x-axis to interval [0,1000000]
    plt::xlim(0, 1000*1000);
    // Add graph title
    plt::title("Sample figure");
    // Enable legend.
    plt::legend();
    // Save the image (file format is determined by the extension)
    plt::save("./basic.png");
}

I compile using

g++ matplotlibcpp.cpp -std=c++11 -I/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12 -lpython3.12

and got this error

In file included from matplotlibcpp.cpp:1:
./matplotlibcpp.h:5:10: fatal error: 'Python/Python.h' file not found
#include <Python/Python.h>
         ^~~~~~~~~~~~~~~~~
1 error generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions