【问题标题】:In VS Code API, how can one get the Python environment path?在 VS Code API 中,如何获取 Python 环境路径?
【发布时间】:2019-01-01 11:38:59
【问题描述】:

在 VSCode 编辑器中实现与 Python 文件一起使用的 Visual Studio 扩展时,如何以编程方式获取当前所选 Python 环境的路径?

我的猜测是它是用python.pythonPath 完成的,但我似乎无法让它工作。如果我直接在扩展 js 中使用它,它会崩溃。我也试过了:

let python = vscode.extensions.getExtension('python');
python.pythonPath

【问题讨论】:

    标签: python visual-studio-code vscode-settings vscode-extensions


    【解决方案1】:

    python.pythonPath 是一个设置,因此您可以使用 VSCode 的通用设置 API 来执行此操作(而不必依赖专门为此公开 API 的 Python 扩展):

    vscode.workspace.getConfiguration("python").get("pythonPath")
    

    【讨论】:

    • 非常感谢,这正是我想要的。不知道我必须获取配置,然后分别获取变量。
    猜你喜欢
    • 2019-11-25
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    • 2015-01-27
    • 2020-10-22
    • 1970-01-01
    相关资源
    最近更新 更多