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

Error loading module matplotlib! #364

Open
AgathaZhang opened this issue Sep 2, 2024 · 2 comments
Open

Error loading module matplotlib! #364

AgathaZhang opened this issue Sep 2, 2024 · 2 comments

Comments

@AgathaZhang
Copy link

AgathaZhang commented Sep 2, 2024

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
Copy link
Author

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

@AgathaZhang
Copy link
Author

AgathaZhang commented Sep 6, 2024

如果想在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"

}

@AgathaZhang AgathaZhang reopened this Sep 6, 2024
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