Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
安装Python+;批处理脚本中的Django_Python_Batch File - Fatal编程技术网

安装Python+;批处理脚本中的Django

安装Python+;批处理脚本中的Django,python,batch-file,Python,Batch File,我想为Windows用户提供一个脚本来安装Python,运行Python-m venv env和pip install-r requirements.txt和Python manage.py runserver 安装Python是我非常不确定的部分。您可以通过简单的命令在后台运行Python安装程序 示例:(有关参考信息,请参阅。) 如果您还想下载python安装程序,可以使用curl。(在Windows 10版本1803或更高版本上提供。请参阅。) 如果希望将所有内容都放在一个.bat脚本中,

我想为Windows用户提供一个脚本来安装Python,运行
Python-m venv env
pip install-r requirements.txt
Python manage.py runserver


安装Python是我非常不确定的部分。

您可以通过简单的命令在后台运行Python安装程序

示例:(有关参考信息,请参阅。)

如果您还想下载python安装程序,可以使用
curl
。(在Windows 10版本1803或更高版本上提供。请参阅。)

如果希望将所有内容都放在一个.bat脚本中,还需要在安装过程之后刷新系统环境变量。通过类似脚本的方式。因此,您可以简单地使用
python
pip
。或者您可以只使用绝对路径

示例脚本如下所示:

@echo off

rem --Download python installer
curl "https://www.python.org/ftp/python/3.9.4/python-3.9.4-amd64.exe" -o python-installer.exe

rem --Install python
python-installer.exe /quiet InstallAllUsers=1 PrependPath=1

rem --Refresh Environmental Variables
call RefreshEnv.cmd

rem --Use python, pip
python -m venv env
pip install -r requirements.txt
python manage.py runserver

pause

谢谢你的回复。你能再解释一下为什么我要刷新系统环境变量吗?这样做是否会产生任何意外的副作用?在我的示例中,安装程序通过在其中添加python安装目录和python脚本目录来修改
PATH
环境变量,但它不会为当前命令提示符会话更新变量。您必须将完整路径写入python和pip可执行文件,或者重新启动命令提示符。
RefreshEnv.cmd
脚本从系统注册表中提取变量,并在当前命令提示符会话中重置它们。据我所知,不应该有任何副作用。
@echo off

rem --Download python installer
curl "https://www.python.org/ftp/python/3.9.4/python-3.9.4-amd64.exe" -o python-installer.exe

rem --Install python
python-installer.exe /quiet InstallAllUsers=1 PrependPath=1

rem --Refresh Environmental Variables
call RefreshEnv.cmd

rem --Use python, pip
python -m venv env
pip install -r requirements.txt
python manage.py runserver

pause