Goal: pick a Python version for the current session and work in a virtual environment, global or per-project.
-
Select the Python version (and optionally the venv choice) in one call:
switchpy :: interactive: version, then venv choice via gum switchpy 3.13 :: version cycle, then venv choice switchpy 3.13 local :: no prompt at all
The second argument answers the venv question up front:
no: no venv, just%PRGS%\pythons\python<version>on the PATH,global: venv under%PYTHON_ROOT%\venvs(shared location,PYTHON_ROOTbeing%PRGS%\pythons),local: venv under%CD%\venvs, namedpython_<version>_<project-folder>.
switchpycreates the venv withpython -m venvwhen missing, repairs a partial venv without replacing an existing interpreter, fixes theVIRTUAL_ENVpath inside itsactivate.bat, setsPYTHON_HOME/PYTHON_VERSION, and defines adeactivatedoskey.For a local venv, it also prepares the project dependencies:
- when one or more
requirements*.txtfiles exist, each file is installed withpython -m pip install -r; - otherwise, when
pyproject.tomlexists, uv is installed when missing anduv sync --all-groupsis run (--frozenis added whenuv.lockexists); - when neither form exists, dependency installation is skipped.
Missing pip is restored with
ensurepipbefore either dependency path. -
Later, from a project that already has a
venvs\folder, activate it without re-runningswitchpy:activate
activate.batdeactivates any current venv, then expects exactly onevenvs\python_*folder and calls itsScripts\activate.bat(it stops with an error on zero or several candidates). -
Leave the venv with
deactivate.
A project senv.bat can chain the global activation with
switchpy 3.13 local, so opening a session in the project lands directly in
the right interpreter and venv: see
per-project senv.
python --version matches the selected version, and the prompt (or
echo %VIRTUAL_ENV%) shows the active venv path.
Related: commands, naming conventions.
