问题描述
每次在 Windows 10 上启动 Python Flask 应用程序时,我都需要设置一长串临时环境变量.现在我想创建一个批处理文件,以便通过双击运行所有设置.如果我复制它们并粘贴到 cmd 提示符下,以下几行运行良好,但我无法在批处理文件中运行它们.
I need to set up a long list of temporary environment variables every time when I start a Python Flask app on Windows 10. Now I would like to create a batch file to run with all settings in one double click. The following lines run well if I copy them and paste to cmd prompt, but I couldn't run them in the batch file.
批处理文件的执行总是在批处理文件中的第二行 venvscriptsactivate
跳闸并退出,如果我在 cmd 处逐行复制和粘贴,则完全没有问题.
The execution of batch file always gets tripped and exited at the 2nd line venvscriptsactivate
in the batch file, which has no issue at all if I copy and paste line by line at cmd.
cd C:pyproject
venvscriptsactivate
set env1=val1
set env2=val2
set FLASK_APP=some.py
flask run
推荐答案
.bat 文件的众多(太多)怪癖之一是,如果您启动另一个 .bat 文件,它不知道返回到哪里.
你需要明确地call
它:
One of the many (far too many) quirks of .bat files is that if you launch another .bat file, it doesn't know where to return to.
You need to explicitly call
it:
call venvscriptsactivate
这篇关于如何在 .bat 批处理文件中启动 Python 虚拟环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!