A legacy service on Python 3.10 and new work on Python 3.13 can share one development machine without either interpreter interfering with the other. The trick is to let pyenv manage the interpreters, let a per-repository .python-version file choose 3.10 only where it is needed, and create the project virtual environment from that pinned interpreter.
This guide shows how to install Python 3.10 alongside Python 3.13 with pyenv from a clean shell: installing pyenv and its build dependencies, adding both interpreters, setting a safe global default, pinning 3.10 in the legacy repository, and checking which binary a shell or CI job actually resolves.
One caveat belongs up front. The Python developer guide's version schedule lists October 1, 2026 as the end-of-life date for Python 3.10, so it no longer receives security patches. pyenv can isolate 3.10 for compatibility, but it cannot extend the interpreter's support. Treat this workflow as a way to manage the migration window, not as a permanent security fix.
Table of Contents
- Why pyenv fits a legacy Python 3.10 project
- Install pyenv and the build dependencies
- Install Python 3.10 and Python 3.13
- Set a safe global default
- Pin Python 3.10 in the legacy repository
- Create the virtual environment from the pinned interpreter
- Verify what each shell and CI job resolves
- Windows: use pyenv-win or a container
- Keep the setup healthy
- Conclusion
Why pyenv fits a legacy Python 3.10 project
pyenv installs each interpreter into its own directory under $(pyenv root)/versions and puts a directory of shims at the front of PATH. When you run python or pip, the shim reads the version selection and forwards the command to the right installation. The selection order is the PYENV_VERSION environment variable, then a .python-version file in the current directory, then the nearest .python-version in a parent directory, and finally the global version file. The official pyenv README describes this shim and selection process in detail.
That gives you two independent choices. The global file decides what python means in a fresh shell. A repository's .python-version file decides what python means inside that repository. A legacy checkout can therefore stay on 3.10 while every new shell and every new project defaults to 3.13.
pyenv manages interpreters, not packages. The pyenv README is explicit that virtual environments are outside its scope, so you still create one with venv (or with the pyenv-virtualenv plugin if you prefer). The Python venv documentation explains that a virtual environment is built on top of a base interpreter and keeps its packages isolated from that base installation. That separation is useful here: pyenv picks the 3.10 interpreter, and the virtual environment keeps the legacy service's dependencies away from everything else.
Install pyenv and the build dependencies
On Linux and macOS, the recommended installation method is the automatic installer:
curl -fsSL https://pyenv.run | bash
On macOS, Homebrew is also a supported option:
brew update
brew install pyenv
The installer places pyenv in ~/.pyenv. Configure your shell startup files and restart the shell:
~/.pyenv/bin/pyenv init --install
exec "$SHELL"
If you installed with Homebrew, use pyenv init --install instead. If you manage dotfiles yourself, review what the command adds and keep the equivalent eval "$(pyenv init - bash)" line in your shell's startup file.
Linux
pyenv builds CPython from source, so the compiler and the development headers for OpenSSL, readline, SQLite, bzip2, xz and related libraries must be present before installation. Recent pyenv releases include a helper for Ubuntu, Debian and Mint:
pyenv install-prerequisites
The python-build plugin documentation notes that this command installs the recommended build dependencies on those distributions. If your pyenv version does not have the command, install the packages directly:
sudo apt update
sudo apt install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl git libncursesw5-dev \
xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev libzstd-dev
The pyenv wiki maintains equivalent package lists for Fedora, openSUSE, Arch Linux, Alpine and other distributions, including the Tcl/Tk 8 packages needed to build older Python versions on newer Fedora releases.
macOS
Install the Xcode command line tools first, then the libraries pyenv needs:
xcode-select --install
brew install openssl@3 openssl readline sqlite3 xz tcl-tk@8 libb2 zstd zlib pkgconfig
Those package names follow the pyenv wiki's current macOS recommendations. Without the development libraries, pyenv install may compile successfully but produce an interpreter that fails later when it tries to load ssl, readline or sqlite3.
Install Python 3.10 and Python 3.13
List the available patches before installing anything:
pyenv install --list | grep -E '^ 3\.(10|13)\.'
Install the specific patch levels your project needs. For example:
pyenv install 3.10.22
pyenv install 3.13.18
Those were current patch levels when this was written. Use the numbers shown by your own pyenv install --list, because the available list changes as releases are added.
You can also run pyenv install 3.10 and pyenv install 3.13. According to the pyenv README's prefix-resolution rules, pyenv install picks the latest known release in that line, while other subcommands pick the latest installed release. That is convenient for a quick experiment, but the explicit patch number is better for a project that other people and CI jobs must reproduce.
Each installation is compiled from source and can take several minutes. The same python-build documentation also notes that checksums are verified automatically when shasum, openssl or sha256sum is available, which is one reason to install through pyenv rather than copying a random binary into place.
Confirm what is installed:
pyenv versions
You should see both patch versions listed alongside system.
Set a safe global default
Set the newer interpreter as the default for new shells:
pyenv global 3.13.18
pyenv version
The second command should report 3.13.18 and say it was set by the file under $(pyenv root)/version. That means a fresh terminal will use 3.13 unless a repository says otherwise.
There are two reasonable global choices:
| Global setting | Effect | Best for |
|---|---|---|
pyenv global 3.13.18 |
Every shell outside a pinned repository uses 3.13 | Teams whose new work targets 3.13 |
pyenv global system |
pyenv stays out of the way until a .python-version file selects a version |
Machines where the OS Python must remain the default |
Avoid pyenv global 3.10.22 unless you genuinely want every unpinned shell to start an end-of-life interpreter. The point of this setup is to make 3.10 the exception, not the default.
Use the full patch number rather than a prefix such as 3.13 when you write the global version. pyenv can resolve a prefix to the latest installed release in that line, but a full patch number makes the choice visible and prevents the default from changing when someone installs another 3.13 patch.
One scheduling note: the same version schedule lists 3.13 in security-only maintenance, with 3.14 and 3.15 in bugfix mode. If your "new work" does not specifically need 3.13, the same workflow works with 3.14 or 3.15 by substituting the newer patch number. The isolation mechanics do not change.
Pin Python 3.10 in the legacy repository
Move into the legacy checkout and set its local version:
cd ~/src/legacy-service
pyenv local 3.10.22
That command writes 3.10.22 into a .python-version file at the repository root. Commit the file so every developer and every CI checkout uses the same interpreter:
cat .python-version
git add .python-version
git commit -m "Pin Python 3.10.22 for the legacy service"
Now verify the resolution from inside the repository:
pyenv version
pyenv which python
The first command should report 3.10.22 (set by /home/you/src/legacy-service/.python-version). The second should print the real interpreter path, something like /home/you/.pyenv/versions/3.10.22/bin/python. Note the difference: outside an activated virtual environment, which python usually shows pyenv's shim, while pyenv which python shows the executable the shim will actually run.
Use the full patch number in .python-version. If you commit 3.10 instead, pyenv may resolve the prefix to the newest installed 3.10 patch, so a teammate who installs a later patch could run a different interpreter without changing the file. A fixed patch number is the reproducible choice for an older service.
If you need a refresher on what the 3.10 line actually contains before isolating it, the guide to getting started with Python 3.10 covers the release's structural pattern matching, clearer error messages and union-type syntax, along with a standard installation walkthrough. Knowing that baseline helps you distinguish an application compatibility problem from a pyenv selection problem.
If the version is not installed on a teammate's machine, pyenv reports that the version is not installed instead of silently falling back to the system Python. That failure is preferable to a test run on the wrong interpreter, and it is a good reason to keep the exact patch in the repository.
Create the virtual environment from the pinned interpreter
With the repository pinned, create the virtual environment from the same shell:
python -m venv .venv
source .venv/bin/activate
python -VV
python -c "import sys; print(sys.executable)"
The version output should start with Python 3.10.22, and the executable path should point inside the repository's .venv directory. The venv documentation explains that the environment records its base interpreter in pyvenv.cfg, so you can open that file later if you need to confirm which pyenv installation created it.
Do not commit .venv. The same venv documentation describes virtual environments as disposable and non-portable: they should be recreated from the project's dependency files rather than copied between machines. Add .venv/ to .gitignore and keep the interpreter choice in .python-version.
A useful ordering rule is to check pyenv which python before running python -m venv. If the shim is still resolving the global 3.13 interpreter, the virtual environment will be built on 3.13. If that happens, delete the environment and recreate it after fixing the pin:
rm -rf .venv
pyenv which python
python -m venv .venv
For a small convenience, python -m venv --upgrade-deps .venv also upgrades the bundled pip during creation on Python 3.9 and later. That is optional, but it avoids starting a fresh environment with an old installer.
Verify what each shell and CI job resolves
Local verification is mostly about checking the same facts at each layer:
| Check | Command | What to look for |
|---|---|---|
| Selected version | pyenv version |
3.10.22 (set by .../.python-version) |
| pyenv shim target | pyenv which python |
A path under ~/.pyenv/versions/3.10.22/
|
| Interpreter version | python -VV |
Python 3.10.22 |
| Virtual environment | python -c "import sys; print(sys.executable)" |
A path inside .venv
|
If a shell ignores the repository pin, check whether PYENV_VERSION is set. The pyenv README puts that environment variable ahead of .python-version, so an exported value from an earlier pyenv shell command or a dotfile will win. Use pyenv shell 3.13.18 for a one-off command and pyenv shell --unset when you are done.
For CI, the .python-version file can be the shared contract even if the runner does not use pyenv. The setup-python action reads a .python-version file by default, and it also accepts an explicit python-version-file input. A GitHub Actions job for the legacy service can look like this:
name: legacy-tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version-file: '.python-version'
cache: 'pip'
- run: python -VV
- run: python -c "import sys; assert sys.version_info[:2] == (3, 10)"
- run: pip install -r requirements.txt
- run: pytest
The assertion step is deliberately blunt. It fails the job if the runner resolves a different Python minor version, which is exactly the kind of drift that a legacy service should not absorb silently.
The setup-python action installs Python from its tool cache or from published builds; it does not use pyenv. That is fine. The important part is that both local development and CI read the same pinned version from .python-version. For a separate 3.13 job, set python-version: '3.13.18' explicitly, or point python-version-file at a second file. Pin the full patch in CI as well, because a range like 3.13 can resolve to a newer patch as runner images are updated.
Windows: use pyenv-win or a container
pyenv does not officially support Windows outside the Windows Subsystem for Linux. Even inside WSL, the Pythons it installs are Linux builds running in a virtual machine, not native Windows interpreters. The pyenv README linked above states this clearly and points Windows users to the pyenv-win fork.
pyenv-win provides a similar command set: install, local, global, versions and which. It can install native Windows Python builds, so it is the better choice when your editor, shell and deployment target are all Windows. Keep the same discipline: pin the patch in .python-version, then verify with pyenv which python and python -c "import sys; print(sys.executable)". Version availability and build behavior differ from the Unix pyenv, so do not assume an exact patch is present until pyenv install -l shows it.
If the legacy service runs in Linux containers in production, a container may be the better fit than a local pyenv installation. The official Python images publish exact tags such as python:3.10.22 and python:3.13.18, which gives you the interpreter and the base operating system in one artifact. That is useful when developers are on mixed operating systems or when you want CI and production to share the same base. Use pyenv for day-to-day local work and a container when platform parity matters more than a native local interpreter.
Keep the setup healthy
pyenv does not automatically refresh its list of available versions. If a release you expect is missing, update pyenv itself or its definitions. With the pyenv-update plugin installed, pyenv update refreshes pyenv and its plugins; with a Git checkout, git pull inside $(pyenv root) does the same job.
When you move the newer service to a new patch, install it, update the relevant .python-version or global setting, and recreate the virtual environment. A virtual environment is tied to the interpreter that created it, so deleting and recreating .venv is safer than trying to upgrade it in place.
For the 3.10 service, the healthier long-term move is to schedule the migration rather than wait for new 3.10 patches that will not arrive. Run the test suite under 3.13, fix the incompatibilities, then change the repository pin and remove the old interpreter once nothing depends on it. pyenv makes that switch a one-line change, but the compatibility work still belongs to the application.
Conclusion
To run Python 3.10 and Python 3.13 side by side, install both with pyenv, set a modern default such as 3.13 (or system), and commit a .python-version file containing the exact 3.10 patch in the legacy repository. Create the virtual environment only after confirming that pyenv which python points at 3.10, and assert the same version in CI so a runner cannot quietly substitute a different interpreter.
The important distinction is between isolation and support. pyenv isolates interpreters, and venv isolates packages, but neither changes the fact that Python 3.10 is past end of life. Use the setup to keep the legacy service stable while you migrate it, not as a reason to postpone the migration.
Top comments (0)