0

I am writing utility which does the following things:

  1. Check Python has installed it or not. if Not Installed, Script downloads the python and install it. In the same session, it executes the python script.

But I am facing one issue here, as soon as the script install python, it's throwing an error while executing the python script as python is not recognized in cmd. But if I run the same program again it works fine.

The problem here is - after installation of Python, the command prompt is not identifying the python command unless I restart the window.

is there any way?

Script is: Getting error at below highlighted section

:errorNoPython

echo.
echo Error^: Python not installed
echo.
echo.
echo Downloading Python 3.7.0...
IF EXIST "%CD%\python-3.7.0.exe" (
  echo Found Installer at "%CD%\python-3.7.0.exe"
) ELSE (
  powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Ssl3, [Net.SecurityProtocolType]::Tls; Invoke-WebRequest -Uri 'https://www.python.org/ftp/python/3.7.0/python-3.7.0.exe' -OutFile '%CD%\python-3.7.0.exe';}"
  echo Python download completed.
)

echo Installing Python...
powershell %CD%\python-3.7.0.exe /quiet InstallAllUsers=0 PrependPath=1 Include_test=0 TargetDir=c:\Python\Python370
setx path "%PATH%;C:\Python\Python370\"

timeout /t 30 /nobreak > nul
echo Python Installation completed.
echo Installing python dependencies.
**start cmd /k python -m pip install requests
start cmd /k python -m pip install pyjavaproperties**
4
  • Does this answer your question? Is there a command to refresh environment variables from the command prompt in Windows? Commented Oct 20, 2020 at 6:57
  • Even after refreshing environment variables, i am getting below error - 'python' is not recognized as an internal or external command, operable program or batch file. But when I ran same command on command prompt one by one after refreshing environment via resetvers.vbs its working properly but via batch file its not working Commented Oct 20, 2020 at 7:45
  • No, Its not working at all. Commented Oct 20, 2020 at 8:30
  • One weird observation. If I run python command manually its working as expected but if i am calling python script via batch file its showin error 'python' is not recognized as an internal or external command, Commented Oct 20, 2020 at 9:23

1 Answer 1

1

In order to reload the environment, you have to close and open cmd.exe

So to get around it, you can set the path and setx

Copy exactly as is, but this will set the path in the current environment:

setx path "%PATH%;C:\Python\Python370\"
set "path=%PATH%;C:\Python\Python370\"
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, but in my case i am installing python and planning to run some python script. so i cant restart the command prompt.
Did you read everything? just copy the set line as is into your code, below the setx line as demonstrated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.