简体   繁体   English

如何在git bash中设置环境变量?

[英]How to set environment variables in git bash?

I use windows and I'm trying to run flask through Git Bash and ConEmu. 我使用Windows,并且试图通过Git Bash和ConEmu运行flask。 I entered the following commands: 我输入了以下命令:

set FLASK_APP=application.py
set FLASK_DEBUG=1
set DATABASE_URL=postgres://someurl
flask run

and this was the result: 结果是:

* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]

Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.

Do I need to write the commands directly into the bash file? 我需要直接将命令写入bash文件吗?

EDIT: I tried setting the variables in bash_profile, but that did not change the results I got. 编辑:我尝试在bash_profile中设置变量,但这并没有改变我得到的结果。 (I did remember to restart my terminal.) (我确实记得重新启动终端。)

You can set it locally for the command: 您可以在本地为命令设置它:

FLASK_APP=application.py FLASK_DEBUG=1 DATABASE_URL=postgres://someurl flask run

Or you can set it permanently for the session: 或者,您可以为会话永久设置它:

export FLASK_APP=application.py
export FLASK_DEBUG=1 
export DATABASE_URL=postgres://someurl 
flask run

The point is: there is no set var=value in git bash as you would use in a CMD. 关键是:在git bash中没有set var=value ,就像在CMD中使用的那样。 set , in bash, has another meaning . bash中的set 具有另一种含义

Change the value of a shell option and set the positional parameters 更改壳选项的值并设置位置参数

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

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