Visual Studio Code - 如何向 python 路径添加多个路径? [英] Visual Studio Code - How to add multiple paths to python path?

查看:70
本文介绍了Visual Studio Code - 如何向 python 路径添加多个路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试用 Visual Studio Code,到目前为止,它看起来很棒(轻巧、快速等).

I am experimenting with Visual Studio Code and so far, it seems great (light, fast, etc).

我正在尝试让我的 Python 应用程序之一运行,该应用程序使用虚拟环境,但也使用不在我的虚拟环境的站点包中的库.

I am trying to get one of my Python apps running that uses a virtual environment, but also uses libraries that are not in the site-package of my virtual environment.

我知道在 settings.json 中,我可以指定一个 python.pythonPath 设置,我已经完成并指向虚拟环境.

I know that in settings.json, I can specify a python.pythonPath setting, which I have done and is pointing to a virtual environment.

我也知道我可以向 python.autoComplete.extraPaths 添加额外的路径,到目前为止我正在添加外部库.问题是,当我调试时,它失败了,因为它没有找到 python.autoComplete.extraPaths 中指定的库.

I also know that I can add additional paths to python.autoComplete.extraPaths, where thus far I am adding the external libraries. The problem is, when I am debugging, it's failing because it's not finding the libraries specified in python.autoComplete.extraPaths.

是否必须为此使用其他设置?

Is there another setting that must be used for this?

谢谢

推荐答案

这对我有用:-

在您的 launch.json 配置文件条目中,指定一个名为env"的新条目,并自己设置 PYTHONPATH.

in your launch.json profile entry, specify a new entry called "env", and set PYTHONPATH yourself.

"configurations": [
    {
        "name": "Python",
        "type": "python",
        "stopOnEntry": false,
        "request": "launch",
        "pythonPath": "${config.python.pythonPath}",
        "program": "${file}",
        "cwd": "${workspaceRoot}",
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ],
        "env": {
            "PYTHONPATH": "/path/a:path/b"
        }
    }
]

这篇关于Visual Studio Code - 如何向 python 路径添加多个路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆