简体   繁体   English

如何为 PyCharm 中的“Shell 脚本”运行配置指定环境变量?

[英]How to specify environment variable for a "Shell Script" run configuration in PyCharm?

My flask app gets its DB credentials from an environment variable.我的 flask 应用程序从环境变量中获取其数据库凭据。 I run it locally by running a small bash file run.sh that just calls flask run with a few options.我通过运行一个小的 bash 文件run.sh在本地运行它,该文件只调用flask run并带有一些选项。

I'd like to be able to have both a 'dev' and 'prod' run configurations in PyCharm, calling this same bash script with a different PG_URL env variable (to tell it to connect to either a local or remote staging / prod DB).我希望能够在 PyCharm 中同时拥有“开发”和“产品”运行配置,使用不同的PG_URL env 变量调用相同的 bash 脚本(告诉它连接到本地或远程登台/产品数据库)。 I don't want to put the credentials in git but am okay having them in a PyCharm run configuration.我不想将凭据放入 git 但可以将它们放入 PyCharm 运行配置中。

Unfortunately when editing run configurations for a shell script there is no place to specify environment variables (while that option is here for a python script), so I'm not sure how to set this up.不幸的是,在编辑 shell 脚本的运行配置时,没有地方可以指定环境变量(而该选项适用于 python 脚本),所以我不确定如何设置它。 This seems like a fairly basic feature, am I missing something obvious?这似乎是一个相当基本的功能,我是否遗漏了一些明显的东西? How do I set this up?我该如何设置?

PyCharm 中的运行/调试配置窗口

You can include the variables in the command to run in the config, for example:您可以在命令中包含变量以在配置中运行,例如:

PG_URL=<url> bash run.sh

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

相关问题 如何在PyCharm的运行/调试配置中将环境变量作为命令行参数传递? - How to pass an environment variable as a command line parameter in Run/Debug configuration in PyCharm? 如何在 PyCharm 中运行 Flask shell? - How to run flask shell in PyCharm? 如何使用临时环境变量运行脚本? - How to run a script with a temporary environment variable? PyCharm“运行配置”要求“脚本参数” - PyCharm “Run configuration” asking for “script parameters” 从PyCharm中的脚本加载环境变量 - Load environment variable from script in PyCharm 如何在python shell(pycharm)上更改环境 - How to change environment on python shell (pycharm) 如何在虚拟环境中运行 shell 执行的 python 脚本 - How to run shell-exectued python script in a virtual environment 没有办法在PyCharm的Sphinx“运行配置”中指定相对路径吗? - Is there no way to specify a relative path in PyCharm's Sphinx “Run Configuration”? 通过 python 脚本设置 shell 环境变量 - Set shell environment variable via python script PyCharm - 如何创建一个运行/调试配置来执行一个使用 Python 脚本作为参数的 .bat 文件? - PyCharm - How to create a Run/Debug Configuration that executes a .bat file which uses a Python script as a parameter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM