Visual Studio Code - 在调试之前激活环境



我目前的设置涉及我编写的boost-python模块。为了调试这个模块,我编写了一个独立的C++程序,该程序从C++程序中调用python脚本。

int main()
{
    try
    {
        PyImport_AppendInittab("oum_export", INIT_MODULE);
        Py_Initialize();
        PyObject *obj = Py_BuildValue("s", "/media/thomas/Data/seafile/Seafile/TUG/ILearnHeart/Anisotropic\ Diffusion/python/oum_cpp_opt.py");
        FILE *file = _Py_fopen_obj(obj, "r+");
        if (file != NULL) 
            PyRun_SimpleFile(file, "D:/seafile/Seafile/TUG/ILearnHeart/Anisotropic Diffusion/python/oum_cpp_opt.py");
        else
            cout << "Script file to execute not found" << endl;
    }
    catch( p::error_already_set ) 
    {
        PyErr_Print();
    }
    Py_Finalize();
}

这应该允许我轻松调试对 Python 模块所做的回调,用 C++ 编写。在调用 vscode 调试器时,程序崩溃并显示错误

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding

这是因为我没有处于正确的蟒蛇环境中。在启动 gdb 之前,如何告诉可视化工作室代码进入正确的环境(即:"源激活aniso_diff &&&gdb oum_export_test"(?

这是我当前的launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "oum_export_test",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/build_linux",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build oum standalone"
        }
    ]
}

我尝试将激活命令合并到构建 preLaunchTask 中,但似乎 vscode 为 gdb 调用了一个新的 shell。

对于大多数人来说,这可能是一个明智的选择,但我刚刚发现最简单的解决方案是在同一个 shell 上调用 vscode 之前简单地激活您想要的环境。

相关内容

  • 没有找到相关文章

最新更新