Skip to content

Instantly share code, notes, and snippets.

@sio sio/venv_temp.bat
Created Sep 19, 2017

What would you like to do?
Set up temporary Python virtual environment on Windows
@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 Copyright 2017 Vitaly Potyarkin
REM Licensed under the Apache License, Version 2.0
if [%1] == [] (
set NAME=temporary_venv
) else (
set NAME=%1
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
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
You can’t perform that action at this time.