0

I want to have a script for Windows users to install Python, run python -m venv env and pip install -r requirements.txt and python manage.py runserver.

Installing Python is the part I'm really unsure about.

nandesuka
  • 269
  • 2
  • 8

1 Answers1

1

You can run python installer in the background via simple command.

Example: (For reference see this.)

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

If you also want to download the python installer you can use curl. (It is available on Windows 10 version 1803 or later. See here.)

If you want to have everything inside one .bat script, you also want to refresh system environmental variables after the installation process. Via script like this. So you can simply use python and pip. Or you can just use absolute paths.

Example script would look like:

@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
  • Thanks for your reply. Can you explain a bit more about why I'll want to refresh system environment variables? Could there be any unintended side effects after doing so? – nandesuka Apr 05 '21 at 23:08
  • In my example the installer modifies the `PATH` environmental variable by adding the python install directory and python Scripts directory there, but it does not update the variable for the current command prompt session. You would either have to write full path to python and pip executables or restart the command prompt. The `RefreshEnv.cmd` script pulls the variables from the system registry and resets them in the current command prompt session. As far as I know there shouldn't be any side effects. – Skulaurun Mrusal Apr 06 '21 at 10:44