如何在 PyCharm 中设置环境变量? [英] How to set environment variables in PyCharm?
问题描述
我已经开始在一个 Django 项目上工作,我想设置一些环境变量而不需要手动设置它们或有一个 bash 文件作为源.
我想设置以下变量:
export DATABASE_URL=postgres://127.0.0.1:5432/my_db_name导出调试=1# 还有其他变量,但它们包含个人信息
我已经阅读了
找到环境变量
并点击...
添加或更改变量,然后点击OK
您可以通过访问您的环境变量/os.html#os.environ" rel="noreferrer">os.environ
导入操作系统打印(os.environ['SOME_VAR'])
I have started to work on a Django project, and I would like to set some environment variables without setting them manually or having a bash file to source.
I want to set the following variables:
export DATABASE_URL=postgres://127.0.0.1:5432/my_db_name
export DEBUG=1
# there are other variables, but they contain personal information
I have read this, but that does not solve what I want. In addition, I have tried setting the environment variables in Preferences-> Build, Execution, Deployment->Console->Python Console/Django Console, but it sets the variables for the interpreter.
You can set environmental variables in Pycharm's run configurations menu.
Open the Run Configuration selector in the top-right and cick
Edit Configurations...
Find
Environmental variables
and click...
Add or change variables, then click
OK
You can access your environmental variables with os.environ
import os
print(os.environ['SOME_VAR'])
这篇关于如何在 PyCharm 中设置环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!