直接上批处理代码(此文件放在安装python的目录):
@echo off
echo
set bk_folder="bk_envfolder"
if not exist %bk_folder% md %bk_folder%
set bkfilenm=%bk_folder%\bk_env%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%
wmic ENVIRONMENT where "name='PYTHON_HOME'" get UserName,VariableValue>%~dp0%bkfilenm%.txt
wmic ENVIRONMENT where "name='Path' and username='<system>'" get UserName,VariableValue >> %~dp0%bkfilenm%.txt
echo Begin to set python environment variable:
echo Please wait a moment......
echo %~dp0
wmic ENVIRONMENT where "name='PYTHON_HOME'" delete
wmic ENVIRONMENT create name="PYTHON_HOME",username="<system>",VariableValue="%~dp0;%~dp0\Scripts\"
wmic ENVIRONMENT where "name='Path' and username='<system>'" set VariableValue="%%PYTHON_HOME%%;%Path%"
echo
echo Done successfully!
echo You can get what done in your the dirctory of the [set.bat] !
echo
wmic ENVIRONMENT where "name='PYTHON_HOME'" get UserName,VariableValue>%~dp0env_new.txt
wmic ENVIRONMENT where "name='Path'" get UserName,VariableValue>> %~dp0env_new.txt
pause