lava / matplotlib-cpp

Extremely simple yet powerful header-only C++ plotting library built on the popular matplotlib
MIT License
4.37k stars 1.13k forks source link

Error loading module matplotlib! #364

Open AgathaZhang opened 4 weeks ago

AgathaZhang commented 4 weeks ago

I am issue now,use Anaconda on Ubuntu 22.04, Python version is 2.7, I installed in a virtualenv. run by vscode, I write tasks.json,becuse I want to debug by vscode GUI "-I", "/home/agatha/.conda/envs/myenv/include/python2.7", "-L", "/home/agatha/.conda/envs/myenv/bin", "-L", "/home/agatha/.conda/envs/myenv/lib/python2.7/site-packages", "-lpython2.7", And than I terminal input "conda activate myenv" and run debug! oh sad occur runtime_error("Error loading module matplotlib!"); 有大佬遇到过类似的问题吗,我已经包含了matplotlib的库路径,可是还是弹出无法加载matplotlib模组,欢迎指教

AgathaZhang commented 3 weeks ago

感觉这样包含不全所有的库路径,但是用Cmake的话又不能单步调试了

AgathaZhang commented 3 weeks ago

如果想在vscode中构建matplotlib并且能够用vscodeGUI单步调试的朋友可以像我这样构建库: 第一步:构建基本的编译器环境,推荐apt install build-essential,这里注意版本依赖不要搞乱了,最好在比较纯净的Linux环境就直接安装build-essential而不是自己去单个下载gcc g++-9 什么的,镜像源我这里推荐ubuntu22.04自带的或者中科大的 第二步:构建python库虚拟环境,推荐Anaconda3,然后再conda create -p /yourpath/env_name python=3.8再 conda activate env_name激活并切到自己的环境 第三步:可以用pip3或者conda install numpy-devel,切记不是conda install numpy,前者有c接口.h,后者只有.py没有.h接口脚本。numpy-devel装完之后这一步对后面的构建很重要 第四步:配置.vscode文件夹中的tasks.json文件,这里最重要的是用"wl" -rpath /yourpath命令把matplotlib运行时需要动态链接的.so目录通知链接器有这么个动态链接行为。 大功告成,可以在单步调试下使用matplotlib了。

附上我的tasks.json

{ "tasks": [ { "type": "cppbuild", "label": "C/C++: g++ in ubuntu Generate active file Agatha", "command": "/usr/bin/g++", "args": [ "-fdiagnostics-color=always", "-g", "${file}", // 打开这个编译当前文件 // "${fileDirname}/*.cpp", // 打开这个编译本文件夹文件

            "-I", "/home/agatha/anaconda/envs/python38/lib/python3.8/site-packages/numpy/core/include",
            "-I", "/home/agatha/anaconda/envs/python38/include/python3.8",       // 这俩是库头文件目录

            "-L", "/home/agatha/anaconda/envs/python38/lib",       // 这个是库实现目录
            "-lpython3.8",

            "-Wl,-rpath=/home/agatha/anaconda/envs/python38/lib",   // 这个是python运行时链接目录

            "-o",
            "${fileDirname}/${fileBasenameNoExtension}",

        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],

        // "presentation": {
        // "reveal": "always",
        // "focus": false,
        // "panel": "shared"
        // },

        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "Tasks generated by the debugger."
    }
],
"version": "2.0.0"

}