简体   繁体   English

python vscode 环境变量不可用

[英]python vscode environment variables not available

I have attempted to follow the directions for environment variables in my project and thought I was doing the correct thing but it does not appear to be working when debugging my python code in vscode.我试图按照项目中的环境变量说明进行操作,并认为我做的是正确的,但是在 vscode 中调试我的 python 代码时它似乎不起作用。

I have a launch.json for a project in.vscode/我有一个 launch.json 项目 in.vscode/

{
    // 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",
            "justMyCode": true,
            "envFile": "${workspaceFolder}/dev.env"
        }
    ]
}

and a dev.env file in my project root和我的项目根目录中的 dev.env 文件

PYTHONUNBUFFERED=1
PASSWORD=abc123
DEBUG_SSO=user.name
CELERY_DEBUG=True
SEND_MAIL=True

when I hit a breakpoint and do "os.getenv('PASSWORD')" it returns None, even though the variable is set in dev.env.当我遇到断点并执行“os.getenv('PASSWORD')”时,它返回 None,即使该变量已在 dev.env 中设置。

Any idea what is wrong with this configuration?知道这个配置有什么问题吗?

This may be due to the relative path being unrecognized.这可能是由于无法识别相对路径。 Add this line to the file "launch.json": "cwd": "${fileDirname}"将此行添加到文件 "launch.json": "cwd": "${fileDirname}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM