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 plugin package "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 ␛[95mNOTICE 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"
71mklink "%PYENV_ROOT%plugins\pyenv-virtualenv\shims\pyenv.bat" "%PYENV_ROOT%plugins\pyenv-virtualenv\patch\pyenv_ptc_%PYENV_VERSION%.bat"
73if %RC% neq 0 goto error7
74REM Permanently activate PATH to "pyenv-virtualenv" utilities
75where activate.bat > "%~dp0.activate_path.~~~"
77if %RC% neq 0 goto activate
78 set /p ACTIVATE_PATH=<"%~dp0.activate_path.~~~"
79 if "%ACTIVATE_PATH%"=="%PYENV_ROOT%plugins\pyenv-virtualenv\shims\activate.bat" goto activate1
81 echo ␛[37mINFO Permanently activating "pyenv-virtualenv" utilities via environment variable PATH ...␛[0m.
82 echo ␛[95mNOTICE Possibly 'Administrator' privileges are required.␛[0m.
83 REM Save the current PATH environment variable content.
84 echo %PATH% > %PYENV_ROOT%plugins\pyenv-virtualenv\PATH_SAVE.txt
85 REM Set the new PATH content permanently
86 setx PATH "%PYENV_ROOT%plugins\pyenv-virtualenv\shims;%PATH%" /m
87 if %RC% neq 0 goto error8
88 set "PATH=%PYENV_ROOT%plugins\pyenv-virtualenv\shims;%PATH%"
91 echo ␛[37mINFO Found "activate.bat" available by "where" command.
92 echo ␛[95mNOTICE But is "%PYENV_ROOT%plugins\pyenv-virtualenv\shims" really the first directory in PATH?
93 echo ␛[37mINFO Open a new console terminal with 'Administator' privileges to clarify this.
94 echo ␛[37mINFO E.g. through repeating to install this package or by simply executing the 'path' command.
98echo ␛[92mSUCCESS Plugin package "pyenv-virtualenv" v%VERSION% for Windows is installed (RC = %RC%).␛[0m
100echo ␛[95mNOTICE: You are recommended to read the documentation available on PyPI and GitHub.␛[0m
102REM Display error messages
106echo ␛[91mERROR Variable "PYENV_ROOT" is not set (RC = %RC%).␛[0m
107echo ␛[37mINFO Check/install/configure package "pyenv" for first. Then try again.␛[0m
112echo ␛[91mERROR Directory "%PYENV_ROOT%" not found (RC = %RC%).␛[0m
113echo ␛[37mINFO Check/install/configure package "pyenv" for first. Then try again.␛[0m
117echo ␛[91mERROR Cannot make directory "%PYENV_ROOT%plugins" (RC = %RC%).␛[0m
118echo ␛[37mINFO Analyze/configure your file access/permissions to "%PYENV_ROOT%". Then try again.␛[0m
122echo ␛[91mERROR Cannot make directory tree in "%PYENV_ROOT%plugins" (RC = %RC%).␛[0m
123echo ␛[37mINFO Analyze/configure your file access/permissions to "%PYENV_ROOT%plugins". Then try again.␛[0m
127echo ␛[91mERROR Failed to install "pyenv-virtualenv" v%VERSION% for Windows (RC = %RC%).␛[0m
128echo ␛[37mINFO Observe the logging why this has going wrong. Reconfigure/repair. Then try again.␛[0m
132echo ␛[91mERROR Cannot find patch file for actual installed "pyenv" version "%PYENV_VERSION%".␛[0m
133copy /a /y /v "%PYENV_ROOT%bin\pyenv.bat" "%PYENV_ROOT%plugins\pyenv-virtualenv\patch\pyenv_ori_%PYENV_VERSION%.bat"
134dir "%PYENV_ROOT%plugins\pyenv-virtualenv\patch\*.*"
135echo ␛[37mINFO Download the latest "pyenv-virtualenv" version from PyPi. Then try again.␛[0m
136echo ␛[37mINFO Alternatively develop the matching patch file for version "%PYENV_VERSION%" and patch the file manually.␛[0m
137echo ␛[37mINFO See the related chapter in the "Development Manual" in documentation "%PYENV_ROOT%plugins\pyenv-virtualenv\docs\html\index.html".␛[0m
141echo ␛[91mERROR Cannot create link to patch file for "pyenv" version "%PYENV_VERSION%" in the "shims" directory of this plugin.␛[0m
142echo ␛[37mINFO Analyze/configure your file access/permissions to "%PYENV_ROOT%plugins\pyenv-virtualenv\shims". Then try again.␛[0m
146echo ␛[91mERROR Cannot permanently prepend "%PYENV_ROOT%plugins\pyenv-virtualenv\shims" to the PATH environment variable.␛[0m
147echo ␛[37mINFO Open new console terminal as 'Administrator', in which you want to try again.␛[0m
149REM Exit program with return code