Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

windows

cmd

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.

like image 392
Ahmed Wagdi Avatar asked Jun 22 '19 12:06

Ahmed Wagdi


2 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"
like image 129
Ahmed Wagdi Avatar answered Oct 13 '22 11:10

Ahmed Wagdi


  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

like image 41
Sagar Suba Avatar answered Oct 13 '22 10:10

Sagar Suba