pyenv-virtualenv for Windows 1.2
A 'pyenv' plugin to manage Python virtual environments, depending on different Python versions, for various Python projects.
Loading...
Searching...
No Matches
install.bat
Go to the documentation of this file.
1@echo off
2setlocal
3REM Windows Command Line Script (Batch) to install the plugin "pyenv-virtualenv".
4REM
5REM Dependencies:
6REM * pyenv
7REM * pyenv-virtualenv
8REM
9REM © 2025 Michael Paul Korthals. All rights reserved.
10REM For legal details see documentation.
11REM
12REM 2025-07-14
13REM
14REM This script is located in the project main directory.
15REM
16REM Simply open it in Windows Explorer or call it by path
17REM in the Windows CMD terminal.
18REM
19REM The script returns RC = 0 or another value in case of
20REM error.
21
22REM Get version string of the package
23set /p VERSION=<"%~dp0.version"
24REM Output installation purpose
25echo.
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
39:endif1
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
46:endif2
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%
52 goto endif3
53:else3
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%
58 goto endif3a
59 :else3a
60 xcopy "%~dp0*" "%PYENV_ROOT%plugins\pyenv-virtualenv" /s /e /k /r /v /y
61 set /a RC=%ERRORLEVEL%
62 :endif3a
63:endif3
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"
72set /a RC=%ERRORLEVEL%
73if %RC% neq 0 goto error7
74REM Permanently activate PATH to "pyenv-virtualenv" utilities
75where activate.bat > "%~dp0.activate_path.~~~"
76set /a RC=%ERRORLEVEL%
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
80:activate
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%"
89 goto success
90:activate1
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.
95 goto success
96:success
97echo.
98echo ␛[92mSUCCESS Plugin package "pyenv-virtualenv" v%VERSION% for Windows is installed (RC = %RC%).␛[0m
99echo.
100echo ␛[95mNOTICE: You are recommended to read the documentation available on PyPI and GitHub.␛[0m
101goto finish
102REM Display error messages
103:error1
104set %RC%=1
105echo.
106echo ␛[91mERROR Variable "PYENV_ROOT" is not set (RC = %RC%).␛[0m
107echo ␛[37mINFO Check/install/configure package "pyenv" for first. Then try again.␛[0m
108goto finish
109:error2
110set %RC%=2
111echo.
112echo ␛[91mERROR Directory "%PYENV_ROOT%" not found (RC = %RC%).␛[0m
113echo ␛[37mINFO Check/install/configure package "pyenv" for first. Then try again.␛[0m
114goto finish
115:error3
116echo.
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
119goto finish
120:error4
121echo.
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
124goto finish
125:error5
126echo.
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
129goto finish
130:error6
131echo.
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
138goto finish
139:error7
140echo.
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
143goto finish
144:error8
145echo.
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
148goto finish
149REM Exit program with return code
150:finish
151del /f "%~dp0.*.~~~"
152exit /b %RC%