[Windows] How to check whether python and pip are installed in the batch script?
A project at hand needs to configure the python environment for your windows machine and install python and pip (the python package management tool). Of course, you do not need to reinstall it if you have already installed python, so the question is, how can we check that python and pip have been installed on your windows system? After debugging for one morning, I finally found a method available:
@ For/f "tokens = 1" % I in ('pip -- version ^ | findstr/C: "pip" ') do ^
Set PIPVER = % I
@ If "% PIPVER %" = "pip" (@ echo Pip deteced !)
@ For/f "tokens = 2" % h in ('python-h ^ | findstr/C: "usage:" ') do ^
Set PYVER2 = % h
@ If "% PYVER2 %" = "python" (@ echo Python deteced !)
Note: you cannot use python -- version. It is estimated that another process is enabled. You can only use python-h to check the version.