Visual Studio 代码 - 调试前激活环境

Visual Studio Code - Activate Env before Debug

我当前的设置涉及我编写的 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

这是因为我不在正确的 anaconda 环境中。在启动 gdb(即:"source activate aniso_diff && gdb oum_export_test")之前,我如何告诉 visual-studio 代码进入正确的环境?

这是我当前的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。

对于你们大多数人来说,这可能是一个 no-brainer,但我只是想出最简单的解决方案是在相同的 shell 上调用 vscode 之前简单地激活您想要的环境.