Created
September 19, 2017 08:45
-
-
Save sio/fbc46ae41607b206ce9099dc8485df34 to your computer and use it in GitHub Desktop.
Set up temporary Python virtual environment on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM This script sets up Python virtual environment in temporary directory | |
REM and runs a new cmd session within. When that cmd session ends, the script | |
REM deletes virtual environment. | |
REM | |
REM Copyright 2017 Vitaly Potyarkin | |
REM | |
REM Licensed under the Apache License, Version 2.0 | |
REM http://www.apache.org/licenses/LICENSE-2.0 | |
SETLOCAL | |
if [%1] == [] ( | |
set NAME=temporary_venv | |
) else ( | |
set NAME=%1 | |
) | |
set VENV=%TEMP%\%NAME% | |
set PYTHON=python | |
echo Creating new virtual environment for Python in %VENV% | |
rmdir /s /q %VENV% 2>NUL | |
%PYTHON% -m venv %VENV% || echo -- venv failed && exit /b | |
call %VENV%\Scripts\activate.bat || echo -- activate failed && exit /b | |
python -m pip install --upgrade pip || echo -- upgrading pip failed && exit /b | |
echo Starting new shell session... | |
echo Virtual environment will be cleared upon exit | |
cmd | |
echo Deleting virtual environment... | |
call deactivate | |
rmdir /s /q %VENV% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment