How do I test if Python is installed on Windows (10), and run an exe to install it if its not installed?

Viewed 136956

I need to run the 2nd command on windows cmd only if the 1st one fails, in another scneario, I want to open python setup after checking if it is installed or not.

I used this command

python --version || path/to/python_install.exe

as I know the || means run if the last command failed. but it only runs the first one.

3 Answers

All of the comments guided me to the right way to do it.

I used this great working code:

:: Check for Python Installation
python --version 3>NUL
if errorlevel 1 goto errorNoPython

:: Reaching here means Python is installed.
:: Execute stuff...

:: Once done, exit the batch file -- skips executing the errorNoPython section
goto:eof

:errorNoPython
echo.
echo Error^: Python not installed
"C:\Program Files\used\systems\innoventiq\accumanager\required\excutables\python-3.7.3-amd64.exe"
  1. Open Command Prompt > Type Python Or py > Hit Enter If Python Is Installed it will show the version Details Otherwise It will Open Microsoft Store To Download From Microsoft Store

  2. Just go in cmd and type where python if it installed it will open a prompt .

Sometimes it may not work if environment variable is not set up, so you can also check by where python in cmd. If where python returns something hot to that path and see for python.exe

try these commands: python3 for the python version over 3.x or python for the rest of the version of python

Related