Managing versions of Python sounds scary, but can be done with ease with the right tooling. This is NOT virtual environments (venvs) — this is about multiple complete installations of different Python language versions.
I won’t talk about venvs because I don’t use or like them (broadly unpopular opinion but I’ll die on this hill).
On Windows platforms, as of version 3.14, Python provides an “installation manager.” Previously (py 3.3 - 3.13), there was the “Python Launcher for Windows” — but 3.14’s installation manager is much more broadly capable and can automatically manage the versions installed for you too.
To install the Python Installation Manager, get it from here: https://www.python.org/downloads/windows/ , specifically the “Python install manager”. Use whichever method you like; I prefer the MSIX installer, but use the store if you want. I won’t think (much) less of you, I promise. You’ll still probably make Santa’s nice list.
Once the manager is installed, you can use it from the command line as follows:
py install 3.14
Installs Python 3.14.
py install 3.10
Installs Python 3.10.
Easy!
You can show what versions you have installed with py -0 (that’s a zero).
Running with specific versions
You can specify a particular version to run any particular command with by adding an extra argument to the py command before any other arguments, like so:
py -3.10 -m pytest # run unit tests on python 3.10
py -3.14 myscript.py # run myscript.py on 3.14
py helloworld.py -foo # run script with args on default python version
py -3.9 add.py 1 2 # run script with args on specific version
Changing system default versions
Typically, the default version is automatically set to the the newest available one you have installed. You can change the default by editing %AppData%\Python\pymanager.json (this should land you in the Roaming AppData folder. Create pymanager.json if it doesn’t exist) and setting the default_tag value, like shown below:
Before the py3.14 pymanager, there was the old py launcher. The old py launcher has a different config method. Edit C:\Users\<you>\AppData\Local\py.ini (create it if it does not exist) and set:
[defaults]python=3.11python3=3.11
to, for example, set the default to 3.11.
Linux: pyenv
On Linux, there is no official installation manager like the Windows one. Instead, there’s a community tool called pyenv which performs nearly the same feature set via on-the-fly $PATH manipulation.
Installation, as detailed in the README, is straightforward for Linux systems:
$ curl -fsSL https://pyenv.run | bash
Security warning
Generally speaking, piping random internet sites to bash is a really bad idea. Don’t make this a habit, and check the code before you run it if you want!
You will need to add the setup hook to your shell startup file. See the README for details (it’s particular to flavor of shell).
Once installed, pyenv can manage your installed versions for you similarly to the Windows manager. Note that unlike the Windows manager, pyenv does not simply download executables — it downloads the Python sourcecode and compiles it on the spot.
pyenv install 3.14
Installs version 3.14
pyenv install 3.10
Installs version 3.10
Running with specific versions
Pyenv offers three different “levels” of selecting versions:
Global: the default for your user
pyenv global 3.10 to set the global default to 3.10.
Local: set a specific version to use by directory. Useful if you have two projects in different folders which need different versions.
cd edgegraph && pyenv local 3.13 to set the default for all work done in edgegraph to 3.13.
Dotfiles used
Pyenv uses a file called .python-version to track this information. Make sure to ignore it in git if needed.
Shell: set a specific version for the currently-open shell session. Useful for quick testing on different versions.
pyenv shell 3.11 to use 3.11 until either you change it again or close the shell session.