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

Unable to compile examples on MacOS #361

Open
ngquyduc opened this issue Jun 5, 2024 · 0 comments
Open

Unable to compile examples on MacOS #361

ngquyduc opened this issue Jun 5, 2024 · 0 comments

Comments

@ngquyduc
Copy link

ngquyduc commented Jun 5, 2024

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.
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

1 participant