我目前的设置涉及一个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();
}
这应该允许我轻松调试用C ++编写的Python模块的回调。在调用vscode-debugger时,程序崩溃并显示错误
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之前,如何告诉visual-studio代码进入正确的环境(即:“source activate aniso_diff&amp;&amp; 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"
}
]
}
我尝试将activate命令合并到构建preLaunchTask中,但似乎vscode为gdb调用了一个新的shell。
答案 0 :(得分:0)
对于大多数人来说,这可能是一个明智的选择,但我只是想到最简单的解决方案是在同一个shell上调用vscode之前简单地激活你想要的环境。