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
deactivate.bat
Go to the documentation of this file.
1@echo off
2REM Windows Command Line Script (Batch) to deactivate virtual environment.
3REM
4REM Dependencies:
5REM * pyenv
6REM * pyenv-virtualenv-init
7REM
8REM © 2025 Michael Paul Korthals. All rights reserved.
9REM For legal details see documentation.
10REM
11REM 2025-07-10
12REM
13REM This script is located in the subfolder "shims"
14REM in the plugin root directory.
15REM
16REM Call it by name in the special Windows CMD terminal,
17REM which has been modified, calling "virtualenv.init".
18REM
19REM The script returns RC = 0 or another value in case of
20REM error.
21REM
22REM NOTE: Command "setlocal" would jeopardize the deactivation.
23REM All local variables are global inside the shell.
24REM Finally, these must be cleaned to reduce risks.
25
26if "%_PYENV_VENV_DEACTIVATE%"=="" goto error0
27if "%_PYENV_VENV_OLD_PROMPT%"=="" goto error0
28if "%_PYENV_VENV_OLD_PATH%"=="" goto error0
29REM Call "%_PYENV_VENV_DEACTIVATE%" and remember its return code
30call "%_PYENV_VENV_DEACTIVATE%" %*
31echo %ERRORLEVEL% > "%~dp0.deactivate_rc.~"
32REM DEBUG: echo Return code: %ERRORLEVEL%
33REM Restore the %_PYENV_VENV_OLD_PROMPT% before activating the virtual environment
34set "PROMPT=%_PYENV_VENV_OLD_PROMPT%"
35REM Restore the %_PYENV_VENV_OLD_PATH% from before activating the virtual environment
36set "PATH=%_PYENV_VENV_OLD_PATH%"
37REM Remove temporary variables
38set _PYENV_VENV_DEACTIVATE=
39set _PYENV_VENV_OLD_PROMPT=
40set _PYENV_VENV_OLD_PATH=
41REM Return deactivate return code
42setlocal
43set /p RC_STR=<"%~dp0.deactivate_rc.~"
44set /a RC=%RC_STR%
45REM DEBUG: echo Return code: %RC%
46del "%~dp0.deactivate_rc.~"
47REM DEBUG: echo Return code: %RC%
48exit /b %RC%
49:error0
50echo ␛[93mWARNING Virtual environment is not activated.␛[0m
51exit /b 0