3REM Windows Command Line Script (Batch) to install the plugin "pyenv-virtualenv".
9REM © 2025 Michael Paul Korthals. All rights reserved.
10REM For legal details see documentation.
14REM This script is located in the project main directory.
16REM Simply open it in Windows Explorer or call it by path
17REM in the Windows CMD terminal.
19REM The script returns RC = 0 or another value in case of
22REM Get version string of the package
23set /p VERSION=<"%~dp0.version"
24REM Output installation purpose
26echo ␛[92mSUCCESS -----------------------------------------------------------------------␛[0m
27echo ␛[92mSUCCESS Installing/docking plugin "pyenv-virtualenv" v%VERSION% for Windows ...␛[0m
28echo ␛[92mSUCCESS -----------------------------------------------------------------------␛[0m
29echo ␛[37mINFO Setting up plugin folder tree ...␛[0m
30REM Check if "pyenv" variable "PYENV_ROOT" is installed
31if not defined PYENV_ROOT goto error1
32REM Check if "pyenv" root folder exists
33if not exist "%PYENV_ROOT%" goto error2
34REM Ensure that subfolder ".\plugins" exists
35if exist "%PYENV_ROOT%plugins" goto endif1
36 mkdir "%PYENV_ROOT%plugins"
37 set /a RC=%ERRORLEVEL%
38 if %RC% neq 0 goto error3
40REM Ensure that required subfolders exist
41if exist "%PYENV_ROOT%plugins\pyenv-virtualenv" goto endif2
42 REM Make "pyenv-virtualenv" folder tree
43 mkdir "%PYENV_ROOT%plugins\pyenv-virtualenv"
44 set /a RC=%ERRORLEVEL%
45 if %RC% neq 0 goto error4
47REM Copy "pyenv-virtualenv" folder tree
48echo ␛[37mINFO Copying files could take some seconds ...␛[0m
49if defined VERBOSE goto else3
50 xcopy "%~dp0*" "%PYENV_ROOT%plugins\pyenv-virtualenv" /s /e /k /r /v /q /y
51 set /a RC=%ERRORLEVEL%
54 set /a VERBOSE=%VERBOSE%
55 if %VERBOSE% neq 0 goto else3a
56 xcopy "%~dp0*" "%PYENV_ROOT%plugins\pyenv-virtualenv" /s /e /k /r /v /q /y
57 set /a RC=%ERRORLEVEL%
60 xcopy "%~dp0*" "%PYENV_ROOT%plugins\pyenv-virtualenv" /s /e /k /r /v /y
61 set /a RC=%ERRORLEVEL%
64if %RC% neq 0 goto error5
65REM Patch the file "pyenv.bat"
66REM Check "pyenv" version
67set /P PYENV_VERSION=<"%PYENV_ROOT%..\.version"
68if not exist "%PYENV_ROOT%plugins\pyenv-virtualenv\patch\pyenv_ptc_%PYENV_VERSION%.bat" goto error6
69echo ␛[37mINFO Activating command forwarding from "pyenv" to "pyenv-virtualenv" ...␛[0m
70if exist "%PYENV_ROOT%plugins\pyenv-virtualenv\shims\pyenv.bat" del /f "%PYENV_ROOT%plugins\pyenv-virtualenv\shims\pyenv.bat"
71echo ␛[37mINFO Creating symbolic link "%PYENV_ROOT%plugins\pyenv-virtualenv\shims\pyenv.bat" → "%PYENV_ROOT%plugins\pyenv-virtualenv\patch\pyenv_ptc_%PYENV_VERSION%.bat" ...␛[0m
74if %ERRORLEVEL% == 0 goto else4
75 REM Running with 'User' privileges.
76 REM Bypassing Windows "'mklink' only as 'Administrator'" limitation.
77 choice /C YN /M "␛[94mDo you permit needed 'Administrator' privileges␛[0m"
78 if not %ERRORLEVEL% == 1 goto error7
79 REM IMPORTATNT: Wait until the process returns
80 powershell -command "Start-Process '%~dp0install_mklink.bat' -Verb runAs -Wait"
83 REM Running with 'Administrator' privileges.
84 powershell -file "%~dp0install_mklink.ps1"
87if %RC% neq 0 goto error7
88if not exist "%PYENV_ROOT%plugins\pyenv-virtualenv\shims\pyenv.bat" goto else5
89 echo ␛[92mSUCCESS Symbolic link "%PYENV_ROOT%plugins\pyenv-virtualenv\shims\pyenv.bat" → "%PYENV_ROOT%plugins\pyenv-virtualenv\patch\pyenv_ptc_%PYENV_VERSION%.bat" has been written.␛[0m
95REM Audit the 'Machine' PATH and the 'User' PATH for path conflicts
96powershell -file install_audit.ps1
98if %RC% neq 0 goto finish
99REM Set the 'shims' directory at the beginning of the 'User' PATH
100REM or 'Machine' if needed or possible.
101powershell -file modify_path.ps1
102set /a RC=%ERRORLEVEL%
103if %RC% neq 0 goto finish
105echo ␛[92mSUCCESS Plugin package "pyenv-virtualenv" v%VERSION% for Windows is installed (RC = %RC%).␛[0m
107echo ␛[95mNOTICE You are recommended to read the unit 'Usage' in the documentation.␛[0m
108echo ␛[37mINFO Execute:␛[0m
109echo ␛[37mINFO "%PYENV_ROOT%plugins\pyenv-virtualenv\docs\html\index.html"␛[0m
111REM Display error messages
115echo ␛[91mERROR Variable "PYENV_ROOT" is not set (RC = %RC%).␛[0m
116echo ␛[37mINFO Check/install/configure "pyenv" for Windows. Then try again.␛[0m
121echo ␛[91mERROR Directory "%PYENV_ROOT%" not found (RC = %RC%).␛[0m
122echo ␛[37mINFO Check/install/configure "pyenv" for Windows. Then try again.␛[0m
126echo ␛[91mERROR Cannot make directory "%PYENV_ROOT%plugins" (RC = %RC%).␛[0m
127echo ␛[37mINFO Analyze/configure your file access/permissions to "%PYENV_ROOT%". Then try again.␛[0m
131echo ␛[91mERROR Cannot make directory tree in "%PYENV_ROOT%plugins" (RC = %RC%).␛[0m
132echo ␛[37mINFO Analyze/configure your file access/permissions to "%PYENV_ROOT%plugins". Then try again.␛[0m
136echo ␛[91mERROR Failed to install "pyenv-virtualenv" v%VERSION% for Windows (RC = %RC%).␛[0m
137echo ␛[37mINFO Observe the logging why this has going wrong. Reconfigure/repair. Then try again.␛[0m
141echo ␛[91mERROR Cannot find patch file for actual installed "pyenv" version "%PYENV_VERSION%" (RC = %RC%).␛[0m
142copy /a /y /v "%PYENV_ROOT%bin\pyenv.bat" "%PYENV_ROOT%plugins\pyenv-virtualenv\patch\pyenv_ori_%PYENV_VERSION%.bat"
143dir "%PYENV_ROOT%plugins\pyenv-virtualenv\patch\*.*"
144echo ␛[37mINFO Download the latest "pyenv-virtualenv" version from PyPi. Then try again.␛[0m
145echo ␛[37mINFO Alternatively develop the matching patch file for version "%PYENV_VERSION%" and patch the file manually.␛[0m
146echo ␛[37mINFO See the related chapter in the "Development Manual" in documentation "%PYENV_ROOT%plugins\pyenv-virtualenv\docs\html\index.html".␛[0m
150echo ␛[91mERROR Cannot create link to patch file for "pyenv" version "%PYENV_VERSION%" in the "shims" directory of this plugin (RC = %RC%).␛[0m
151echo ␛[37mINFO Analyze/configure your file access/permissions to "%PYENV_ROOT%plugins\pyenv-virtualenv\shims" or decide to call this script as 'Administrator'. Then try again.␛[0m
153REM Exit program with return code
155if exist "%~dp0.*.~~~" del /f "%~dp0.*.~~~"
159REM --- END OF CODE ----------------------------------------------------