Visual Studio Code - 在调试之前激活环境
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
这是因为我没有处于正确的蟒蛇环境中。在启动 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 之前简单地激活您想要的环境。
相关文章:
- 枚举环境变量的惯用C++14/C++17方法
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 创建一个包含 c++ 默认值的环境文件
- 定义C++新的环境变量并在 bat 文件中使用它
- 用于在并发环境中访问 MMIO 的软件模式
- docker 构建失败:无法设置环境变量
- 如何在不传递命令行参数的情况下在 c++ 中设置环境变量
- C++环境变量
- 在编译时为运行时设置环境变量
- 在 3ds Max 中更新进度条后,环境和效果 UI 不刷新
- 如何使用可视化代码和平台IO将环境变量注入CPP文件?
- 访问 PlatformIO 中的外部环境变量
- 在 Azure DevOps 构建管道中使用英特尔C++编译器为 Linux 环境构建C++代码
- 如何在日食中激活自动建议?
- 如何注册枚举类型到QJSEngine,以便在脚本环境中使用?
- WSL 看不到环境变量
- QT5 信号不会激活插槽内的功能
- 启动 dll 时 C# 环境堆栈溢出
- "C.UTF-8" C++ Windows 上的语言环境?
- Visual Studio Code - 在调试之前激活环境