Create a virtual environment with a specific Python version

Select an installed interpreter with virtualenv or invoke that interpreter’s venv module, then verify which Python and pip the environment uses.

Best practices
Python programming and application logging

Choose the interpreter first. With virtualenv, pass its path using -p; with the standard library's venv, run the desired interpreter's -m venv command. You do not need virtualenv solely to create an environment for a different installed Python version.

Select an interpreter with virtualenv

Install the tool using your supported Python tooling setup, for example with pipx:

pipx install virtualenv
virtualenv -p /usr/bin/python3.13 myenv

The path is an example; it must identify an installed interpreter that your virtualenv release supports. If virtualenv is installed as a module in your current interpreter, the equivalent form is:

python -m virtualenv -p /usr/bin/python3.13 myenv

On Bash or zsh, activate and verify it:

source myenv/bin/activate
python --version
python -c "import sys; print(sys.executable)"
python -m pip --version

Using python -m pip ties package installation to that Python, avoiding an unrelated pip command on PATH.

Use venv directly

When the desired Python includes venv support:

python3.13 -m venv myenv

venv creates an environment from the interpreter executing it. It has no -p selector, but choosing the executable achieves the version selection directly. On some distributions, venv support is supplied by an additional distribution package.

Choice How you select Python
Standard-library venv Invoke the desired interpreter with -m venv.
Third-party virtualenv Pass an interpreter path or supported discovery specification with -p.
Conda Request an available Python package version when creating the environment.

Creation speed and supported old interpreters depend on tool versions and configuration. Do not assume modern virtualenv supports Python 2; obsolete runtimes require a separately evaluated legacy toolchain.

Install a missing interpreter first

Use your operating system's supported packages or an interpreter manager. A third-party Ubuntu PPA is not a general Debian installation method. pyenv can list available releases with pyenv install --list and install a selected release; use its resulting interpreter path with either tool.

Conda can create an environment with a version constraint, for example conda create -n myenv python=3.13, when a compatible build exists in the configured channels. It cannot guarantee every historical version on every platform.

FAQ

How do I find installed versions? Use command -v python3.12 python3.13 on Unix-like systems or pyenv versions for pyenv-managed installations. A scan of /usr/bin alone misses interpreters installed elsewhere.

What about Windows? virtualenv -p C:\Python313\python.exe myenv selects that installed interpreter. With a compatible Python launcher, py -3.13 -m venv myenv is another option. To run -m virtualenv through a selected interpreter, the module must be available to it.

Are installed packages isolated? The default environment isolates its site-packages, but options such as system-site-package access change that behavior. Verify the interpreter and install with its -m pip command.

References

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting