Windows安装C++绘图工具(matplotlib-cpp)全过程排错指南

用C++绘制图表的第三方库:matplotlib-cpp
https://github.com/lava/matplotlib-cpp

  1. 下载matplotlib-cpp

    git clone https://github.com/lava/matplotlib-cpp.git
    

    太慢的话用这个,一样的:

    git clone https://gitee.com/cugcuiyc/matplotlib-cpp.git
    

    在这里插入图片描述

  2. 先包含上库的路径
    我用的Clion。

    include_directories("E:/CppThirdParty/matplotlib-cpp") # 换你自己的
    

    在这里插入图片描述
    试试官网的例子,能运行了不?

    #include <matplotlibcpp.h>
    namespace plt = matplotlibcpp;
    int main() {
        plt::plot({1,3,2,4});
        plt::show();
    }
    

    在这里插入图片描述

  3. 排错

    1. 没有<Python.h>
      在这里插入图片描述
      解决方案:https://github.com/lava/matplotlib-cpp/issues/282
      需要找到Python库所在位置
      在这里插入图片描述
      在这里插入图片描述

    2. 找不到<numpy/arrayobject.h>
      在这里插入图片描述
      解决方案:https://github.com/lava/matplotlib-cpp/issues/46
      手动添加头文件路径,找到下载的numpy库,头文件在core/include里面
      在这里插入图片描述
      在这里插入图片描述

    3. redefinition of ‘struct matplotlibcpp::detail::select_npy_type’在这里插入图片描述
      解决方案:点进去看看,注释掉这两行即可 在这里插入图片描述

    4. Python path configuration报错:atal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
      Python runtime state: core initialized
      ModuleNotFoundError: No module named ‘encodings’
      在这里插入图片描述
      盲猜是环境变量的问题:
      在这里插入图片描述
      解决方案:添加python路径到环境变量,变量名为PYTHONHOMEPYTHONPATH。我用的Anaconda的base环境:
      在这里插入图片描述
      在这里插入图片描述
      重启。

    5. This application failed to start because it could not find or load the Qt platform plugin “windows”
      in “”.
      在这里插入图片描述解决方案:确保在当前python环境下安装好tkinter库。在 .matplotlib 下新建一个文件 matplotlibrc(无后缀名) 添加内容: backend: TkAgg
      在这里插入图片描述

行吧,几乎把Issues全过了一遍。终于,运行成功!
在这里插入图片描述
注意,你可能还会报这个错:
ImportError: DLL load failed while importing ft2font
解决方案:matplotlib版本太高:https://blog.csdn.net/weixin_48122003/article/details/109215715

谁闲的没事用C++调python的包画图啊!

  • 7
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

伯明翰谢老二

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值