如何将 optirun 添加到 vscode 调试选项?

how to add optirun to vscode debug options?

我使用 manjaro 并想使用 vscode 工具来调试我的 python 程序,但我使用 CUDA,所以我通常使用这样的命令:

optirun ipython program.py arg1 arg2

当我尝试调试程序时,没有调用 optirun,所以我无法访问 GPU,如何在 python(或 ipython)之前调用 optirun?

我尝试更改 settins.json 和 launch.json 以将其添加到命令中,但它不起作用。

谢谢。

您可以尝试通过 "python.pythonPath" setting.

编辑您的 launch.json 以指向 optirun 作为您的 Python 解释器

这就是我所做的并且有效。

  1. 创建一个 bash 脚本,随便命名,假设 script.sh
#!/bin/bash

optirun python "$@"
  1. .vscode/launch.json 中将 "pythonPath" 设置为 ./script.sh
    这是一个例子launch.json
{
   // Use IntelliSense to learn about possible attributes.
   // Hover to view descriptions of existing attributes.
   // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
   "version": "0.2.0",
   "configurations": [


       {
           "name": "Python: Current File",
           "type": "python",
           "request": "launch",
           "program": "${file}",
           "console": "integratedTerminal",
           "linux": {
               "pythonPath": "./script.sh"
           },
       }
   ]
}
  1. 现在它应该可以正常工作了。

我在 python 中调试 OpenCL 应用程序时也遇到了同样的问题。我的 Nvidia 显卡由 optirun 管理。 $@ 将 vscode 提供的所有命令行参数传递给 python 解释器。