matplotlib-cpp
matplotlib-cpp copied to clipboard
is it supported on windows?
Is it supported on windows? if so how do I add the python header file.
I managed to get it running on windows. I'm using visual studio community 15 and cmake.
Here are the steps.
-
install python and matplotlib .. don't forget to add python folder it to your PATH.
-
add matplotlibcpp.hpp to your project include folder.
-
on you cmake list file add this.
find_package(PythonLibs REQUIRED)
INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_DIRS} )
link_directories( ${PYTHON_LIBRARIES})
target_link_libraries( targetname ${PYTHON_LIBRARY})
note that if you have to use other libraries add them here to.
- then on your matplotlibcpp change the include to this.
#include <Python.h>
instead of<python27/Python.h>
@saykou Can you explain how you got it working on Windows in more detail? I'm also using Visual Studio. I just downloaded CMake and I'm especially having trouble with the 3rd step. I have a Python compiler installed (Canopy) and working, I switched <python27/Python.h> to <Python.h> and matplotlibcpp.h is the header file for the given minimal example: #include "matplotlibcpp.h" namespace plt = matplotlibcpp; int main() { plt::plot({1,2,3,4}); plt::show(); }
I'm still getting errors when I run/build in main.cpp though.
@spletts you have to install python 2.7 for windows, and don't forget in the options when installing to add python to path
I added some codes for Windows support. https://github.com/lava/matplotlib-cpp/tree/master/contrib Just you have to edit the third line of WinBuild.cmd before you run it.
Unfortunately, it does not work for me on Windows 10, VS 10. Could you please specify which path variables you have set and how you modified your cmake file? Apparently, cmake goes and finds a python installation of mine which is not included in any paths, which get's me kind of confused...
If you talk about contrib, you got to run WinBuild.cmd intead of cmake. All the path are written in there.
I didn't write it for visual studio 2010 (Does it support c++11 at all?)
Hi, I tried to use this library in visual studio but I'm getting an error related to qt. The error is: This application failed to start because it could not find or load the Qt platform plugin "windows"
"Fixed it" changing python 2 for python3, weird
Hi, I tried to make it work in VS 2015 community. Also tired the cmd in contrib, which was able to build after not including numpy. But that one need debug version of python. When I try to build it up within VS, I got a lot of linking errors as listed, any ideas what's going on? Any help is appreciated. Thanks.
Severity Code Description Project File Line Suppression State Error LNK2001 unresolved external symbol __imp__PyDict_New PyPlotTrial G:\Work\API\Project\Machine VEC\VEC Lite-2018\SourceCode\PyPlotTrial\PyPlotTrial\PyPlotTrial.obj 1 Error LNK2001 unresolved external symbol __imp__PyDict_SetItemString PyPlotTrial G:\Work\API\Project\Machine VEC\VEC Lite-2018\SourceCode\PyPlotTrial\PyPlotTrial\PyPlotTrial.obj 1 Error LNK2001 unresolved external symbol __imp__PyFloat_FromDouble PyPlotTrial G:\Work\API\Project\Machine VEC\VEC Lite-2018\SourceCode\PyPlotTrial\PyPlotTrial\PyPlotTrial.obj 1 Error LNK2001 unresolved external symbol __imp__PyFunction_Type PyPlotTrial G:\Work\API\Project\Machine VEC\VEC Lite-2018\SourceCode\PyPlotTrial\PyPlotTrial\PyPlotTrial.obj 1 Error LNK2001 unresolved external symbol __imp__PyImport_Import PyPlotTrial G:\Work\API\Project\Machine VEC\VEC Lite-2018\SourceCode\PyPlotTrial\PyPlotTrial\PyPlotTrial.obj 1 Error LNK2001 unresolved external symbol __imp__PyList_New PyPlotTrial G:\Work\API\Project\Machine VEC\VEC Lite-2018\SourceCode\PyPlotTrial\PyPlotTrial\PyPlotTrial.obj 1
one update, figured out the root cause; My python is 64 bit while I was building win32 application. Now, it worked. THANKS!
Is this working on Windows 10 and Visual Studio 2019?
i can run it now on windows10 with VS2015 + python 3.6.5, great tools ~~~~
i can run it now on windows10 with VS2015 + python 3.6.5, great tools ~~~~
Any chance you could list out your installation steps? I'm on Windows 10, Visual Studio 19. Also have vcpkg installed.
@sharmaabhishekk I just managed to run it on VS2019 & python 3.7. it was not easy.
Where exactly your code fails? compilation or runtime? release or debug?
for now I only managed to make it work for release builds, and using non-deafult backend:
plt::backend("WX");
plt::plot({ 1,3,2,4 });
plt::show();
It works on Windows with MinGW as well.
Used the minimal example from the Readme. Compiled using the following:
g++ main.cpp -std=c++11 -I C:/Python310/include -IC:/Python310/Lib/site-packages/numpy/core/include -LC:/Python310/libs -lpython310
.
Caveats: Installed numpy globally for Python using pip. Have the python310.dll in the build / dist folder of your project.
The minimal example worked with the compilation flag -DWITHOUT_NUMPY as well. In that case the compilation command is:
g++ main.cpp -std=c++11 -I C:/Python310/include -LC:/Python310/libs -lpython310
.
Of course, please change the Python versions accordingly.
@pratikmahamuni1843 i tried to do it on windows 11, i am using visual studio code this is the path that i added: g++ scheduling_algo.cpp -std=c++11 -I C:/Users/Anshul Pareek/AppData/Local/Programs/Python/Python310/include -I C:/Users/Anshul Pareek/AppData/Local/Programs/Python/Python310/Lib/site-packages/numpy/core/include/numpy -L C:\Users/Anshul Pareek/AppData/Local/Programs/Python/Python310/libs -lpython310
this is the error that i get: g++: error: Pareek/AppData/Local/Programs/Python/Python310/include: No such file or directory g++: error: Pareek/AppData/Local/Programs/Python/Python310/Lib/site-packages/numpy/core/include/numpy: No such file or directory g++: error: Pareek/AppData/Local/Programs/Python/Python310/libs: No such file or directory