PythonPython Environment and Development ToolsPython environment setup
How do you manage multiple Python versions on one machine?
Question 29 of 88 · Updated
On this page
- 1. Interpreter versions and virtual environments solve different problems
- 2. Discover which interpreters are installed
- 3. Install versions side by side using platform-appropriate tooling
- 4. Create one virtual environment per project
- 5. Using a Python version manager
- Example: pyenv
- Example: uv
- Example: Conda
- 6. Practical tested example: separate interpreter-associated environments
- 7. Select the correct interpreter in editors, subprocesses and notebooks
- 8. Record supported versions in project metadata
- 9. Test compatibility across versions
- 10. How to upgrade a project to another Python version
- 11. Common mistakes
- Frequently asked questions
- Can Python 3.11 and 3.13 coexist?
- Can venv install an arbitrary Python version?
- Does activating a virtual environment change the system Python?
- Do I need a version manager?
- Why does an IDE still use an old version after installing a new one?
- Interview-ready answer
- Key takeaways
- Official references
Install the required Python interpreter versions side by side, select the correct interpreter for each project, and create a separate virtual environment from that interpreter. A version manager can simplify downloading and selecting Python releases, while a virtual environment isolates project dependencies.
For example, a legacy application might require Python 3.11 while a newer application targets Python 3.13. Both can coexist on one computer without changing the system Python or sharing incompatible packages.
The essential rule is to select the interpreter before creating the environment, then use that environment consistently for running code, installing packages, debugging and testing.
1. Interpreter versions and virtual environments solve different problems#
| Tool or concept | Responsibility |
|---|---|
| Python installation | Provides a particular interpreter version and its standard library |
| Version manager | Installs or selects interpreter versions according to its supported workflow |
| venv | Creates a project environment from an existing interpreter |
| pip | Installs Python distributions into the selected environment |
| IDE or notebook kernel | Selects the interpreter used for development or execution |
Creating a virtual environment with Python 3.13 does not turn it into a Python 3.11 environment. Install the required base interpreter first.
A useful conceptual layout is:
Machine
|
+-- Python 3.11 installation
| +-- legacy-project/.venv
| +-- legacy dependencies
|
+-- Python 3.13 installation
+-- new-project/.venv
+-- new dependenciesThe base runtime and installed dependencies are separate concerns. Different projects can also use separate environments based on the same Python version.
2. Discover which interpreters are installed#
On Linux or macOS, inspect the commands your shell can resolve:
BASHcommand -v python3 command -v python3.11 command -v python3.13
These commands report a path when the requested executable is found through the shell's resolution rules. An unavailable command does not necessarily mean the interpreter is absent from the machine; it might be installed outside PATH.
If an interpreter is available, check its version explicitly:
BASHpython3.13 --version
On Windows, when the traditional Python launcher is installed, the following commands can list registered installations and choose a version:
POWERSHELLpy -0p py -3.13 --version
Launcher and installation-manager commands differ across Windows installations. Consult the documentation for the installed launcher or manager if these commands are unavailable.
Within a running Python process, use:
PYTHONimport sys print(sys.version.split()[0]) print(sys.executable)
The version and executable path together help distinguish environments. Two executables may report the same version but have different installation paths, build settings or package directories.
3. Install versions side by side using platform-appropriate tooling#
Several approaches are valid.
Windows: Use the official Python installation workflow or an approved version-management tool. Choose the required interpreter through a supported launcher or an explicit executable path.
macOS: Use official Python installers or an approved package/version manager. Check which installation provides the desired executable before creating a project environment.
Linux: Use a trusted distribution package manager where it supplies the required interpreter. A user-level version manager can be useful when the operating-system repositories do not offer the required release.
Do not replace the Python executable that the operating system relies upon. System utilities may depend on the distribution's Python installation and package set. Prefer separately installed interpreters and project-level environment selection.
Check that the desired Python release is compatible with the operating system, architecture and application dependencies. An old interpreter may lack security updates even if the application can still run on it.
4. Create one virtual environment per project#
Assume Python 3.11 and Python 3.13 are already installed and available under these command names on Linux or macOS.
For the legacy application, from its project directory:
BASHpython3.11 -m venv .venv .venv/bin/python --version
For the new application, from its own project directory:
BASHpython3.13 -m venv .venv .venv/bin/python --version
The two environments are independent despite sharing the directory name .venv. Each resides inside its own project.
On Windows, with a compatible Python launcher, the corresponding creation commands are:
POWERSHELLpy -3.11 -m venv .venv
and, in the other project's directory:
POWERSHELLpy -3.13 -m venv .venv
Verify the selected environment executable using .venv\Scripts\python.exe on Windows.
The two-version scenarios are illustrative: the local test environment provides Python 3.13.5, not Python 3.11. Actual cross-version execution was not tested.
Once the intended environment exists, install dependencies through its own interpreter. For example:
BASH.venv/bin/python -m pip install -r requirements.txt
This assumes pip is available, the requirements file exists, and compatible approved distribution artifacts can be obtained. A virtual environment can be used directly without activating it in a shell.
5. Using a Python version manager#
Version managers help when maintaining several interpreter versions manually becomes inconvenient.
| Tool | Typical role |
|---|---|
| pyenv | Install and select Python versions, particularly in Unix-like development workflows |
| uv | Manage Python installations and project environments in supported workflows |
| Conda | Manage environments including available Python interpreter packages and other packaged dependencies |
| Python launcher or installation manager on Windows | Discover or select supported installed runtimes according to its capabilities |
These tools have different installation, resolution and configuration models. Choose one consistent workflow for a given project. Mixing several managers without understanding their precedence can make interpreter selection harder.
Example: pyenv#
After installing and configuring pyenv according to its official documentation, an illustrative workflow is:
BASHpyenv install --list pyenv install 3.13.5 pyenv local 3.13.5 python --version python -m venv .venv
The example version is a fixed teaching value, not a recommendation to use that particular patch release today. Choose an approved, supported patch version for the actual project.
pyenv local commonly records the selected version in a .python-version file and uses shell integration to select the runtime. Its version selection does not by itself install project dependencies. Installation may require a network connection and platform-specific build prerequisites.
pyenv is unavailable locally, so these commands were not executed.
Example: uv#
In a supported uv workflow, common commands include:
BASHuv python list --only-installed uv python install 3.13 uv venv --python 3.13 .venv
The first command discovers available installed interpreters. The installation and environment-creation commands depend on the installed uv version, approved interpreter sources and platform support.
An offline installed-interpreter listing was tested locally:
BASHuv python list --only-installed --offline
The output listed CPython 3.13.5 installations or executable aliases. No interpreter was downloaded and the other uv commands were not exercised in this test.
Example: Conda#
After Conda is installed and configured, a project can request a Python version as part of a named environment:
BASHconda create --name legacy-demo python=3.11 conda create --name new-demo python=3.13 conda activate legacy-demo python --version
The requested versions must be available from the approved configured channels. Conda can manage non-Python packages as well as Python packages, making it useful for certain scientific workflows. These commands are illustrative and were not run because Conda is unavailable locally.
6. Practical tested example: separate interpreter-associated environments#
Even when two different minor versions are not installed, the mechanism of selecting an explicit interpreter and creating separate environments can be tested.
The local Linux environment contains Python 3.13.5 accessible through both /usr/bin/python3 and /opt/pyvenv/bin/python. The following experiment was run in a temporary working directory:
BASH/usr/bin/python3 -m venv --without-pip .venv-a /opt/pyvenv/bin/python -m venv --without-pip .venv-b .venv-a/bin/python -c 'import sys; print(sys.version.split()[0]); print(sys.prefix != sys.base_prefix)' .venv-b/bin/python -c 'import sys; print(sys.version.split()[0]); print(sys.prefix != sys.base_prefix)'
Output:
3.13.5
True
3.13.5
TrueBoth environments were created successfully and both reported the same Python version. The True values indicate standard virtual-environment prefix separation.
The executable paths are specific to the test machine. Replace them with the intended installed interpreters on your own system. The --without-pip option is used here to keep this interpreter-selection experiment independent of pip provisioning; omit it when creating an ordinary development environment that needs pip.
This experiment establishes separate environment selection, not compatibility between different Python versions.
7. Select the correct interpreter in editors, subprocesses and notebooks#
A developer may create the correct environment but still run a program with another interpreter.
In VS Code or PyCharm, select the project's environment executable in the Python tooling. In Jupyter, select a kernel associated with the intended environment. In automated jobs, use a documented interpreter selection or explicit executable path.
For a Python program that needs to launch another Python process using the same interpreter, sys.executable is useful:
PYTHONimport subprocess import sys child_prefix = subprocess.check_output( [sys.executable, "-c", "import sys; print(sys.prefix)"], text=True, ).strip() print(child_prefix == sys.prefix)
Output in the local virtual-environment test:
TrueThis example invokes a child interpreter using an explicit path rather than relying on PATH to resolve the command name python. It assumes sys.executable identifies an available executable.
For an intentional compatibility test against another interpreter, select that interpreter explicitly instead.
8. Record supported versions in project metadata#
For a packaged Python project, the standard project metadata in pyproject.toml can include the supported Python version range.
For example:
TOML[project] name = "example-project" version = "0.1.0" requires-python = ">=3.11,<3.14"
The metadata is an illustrative compatibility declaration. It does not install a runtime or prove the project works on every allowed version. Publish only a range supported by the project's testing and dependency requirements.
A tool-specific interpreter-selection file can also record the development interpreter version. For example, a .python-version file understood by the chosen version manager may pin a particular release. Its exact interpretation is tool-dependent.
Record dependencies separately using the project's approved requirements or locking workflow. An interpreter pin alone cannot reproduce third-party package versions.
9. Test compatibility across versions#
Projects supporting several Python versions should test the relevant versions in CI. For example, a library supporting Python 3.11 through 3.13 should run its test suite in independent environments for those supported minor versions.
Tools such as tox or nox can coordinate test environments, while CI platforms can run a matrix of Python versions. The configuration must reflect the actual interpreter availability, dependency support and project's release policy.
A simple runtime guard can detect an unsupported minimum version:
PYTHONimport sys if sys.version_info < (3, 12): raise RuntimeError("Python 3.12 or newer is required") print("Compatible")
Expected output when run on the locally available Python 3.13.5:
CompatibleA version guard is not a substitute for testing. Python minor releases can differ in syntax, standard-library APIs, behaviour and third-party artifact availability.
Test on the actual required versions instead of assuming that a passing test on one version guarantees compatibility with another.
10. How to upgrade a project to another Python version#
Treat an interpreter upgrade as an environment rebuild:
- Review application dependencies and supported runtime versions.
- Install the target Python version side by side.
- Create a fresh virtual environment from the target interpreter.
- Install reviewed dependencies using the project's dependency workflow.
- Run unit tests, integration tests and relevant performance checks.
- Update editor, notebook, CI and deployment configuration.
- Retain the previous working environment until rollback is no longer necessary.
Do not copy installed packages directly from an older environment into a new interpreter environment. Binary extensions and package metadata may be incompatible.
Although venv offers some upgrade-related options for specific situations, creating a fresh environment is a clear default for changing interpreter versions and checking compatibility.
11. Common mistakes#
Using an ambiguous python command. Check sys.executable and the version. PATH precedence, shell aliases and version-manager shims can all affect resolution.
Using pip from another environment. Invoke pip through the intended interpreter using python -m pip or its explicit executable path.
Sharing one virtual environment across unrelated projects. Separate dependency versions and project lifecycles. Two applications may require incompatible versions of the same distribution.
Assuming every package works on every Python version. Check the package's metadata, supported wheels and build requirements.
Changing system Python to satisfy an application. Keep operating-system tooling intact and use an isolated project runtime.
Checking in the virtual environment directory. Record the runtime and dependencies in project configuration rather than committing machine-specific generated interpreter files.
Assuming version-manager configuration applies to every process. Verify the editor, shell, test runner, notebook kernel and service process independently.
Frequently asked questions#
Can Python 3.11 and 3.13 coexist?#
Yes, with appropriate side-by-side installations. Select the required interpreter explicitly and create a project environment based on it.
Can venv install an arbitrary Python version?#
No. The ordinary venv command creates an environment based on an existing interpreter. Install or obtain the required interpreter first.
Does activating a virtual environment change the system Python?#
Normally no. Activation adjusts command resolution in the current shell. It does not replace the operating-system interpreter.
Do I need a version manager?#
Not necessarily. Explicit paths or installed version-specific commands are sufficient for many projects. A version manager helps when regularly maintaining multiple runtime versions.
Why does an IDE still use an old version after installing a new one?#
Its project interpreter configuration may still point to the previous installation. Select the intended environment and verify the actual runtime from within the application.
Interview-ready answer#
To manage multiple Python versions, install the necessary interpreters side by side using trusted installers or a version manager such as pyenv, uv or Conda. Select the required interpreter for each project, create a dedicated virtual environment from it, and install dependencies into that environment using its associated installer. Record the supported Python version and dependency specification, configure development tools and CI to use the correct interpreter, and test the versions the project claims to support. Avoid changing the operating system's Python installation or copying environments between incompatible interpreter versions.
Key takeaways#
- Interpreter version selection and dependency isolation are separate tasks.
- Choose a specific interpreter before creating a virtual environment.
- Use the environment's executable consistently across development and automation.
- Record supported runtime versions and validate them through real tests.
- Rebuild isolated environments when migrating to another Python version.
Official references#
- Python documentation — Using Python on different platforms
- Python documentation — venv
- Python documentation — sys.executable
- pyenv project documentation
- uv documentation — Installing and managing Python
- Conda documentation — Managing environments
- Python Packaging User Guide — pyproject.toml specification
Verification note: Local Linux testing confirmed Python 3.13.5 through two executable paths, successful creation of two separate venv directories without pip, prefix checks, subprocess interpreter selection, a minimum-version guard and uv's offline installed-interpreter listing. Only Python 3.13.5 was available; cross-version execution, pyenv, Conda, runtime downloads, Windows commands and IDE configuration were not tested. References are supplied from established technical knowledge under the authorised offline research exception and were not checked live.
References
- 1.Python documentation — Using Python on different platformsdocs.python.org
- 2.Python documentation — venvdocs.python.org
- 3.Python documentation — sys.executabledocs.python.org
- 4.pyenv project documentationgithub.com
- 5.uv documentation — Installing and managing Pythondocs.astral.sh
- 6.Conda documentation — Managing environmentsdocs.conda.io
- 7.Python Packaging User Guide — pyproject.toml specificationpackaging.python.org
Related questions
Explore other topics:Forward Deployed EngineeringMachine LearningSQL: Structured Query LanguageAI System Design