Skip to content

Commit

Permalink
Fix some outdated documentation discussing Python environments (#6058)
Browse files Browse the repository at this point in the history
Starting on #5966 noticed various
problems
  • Loading branch information
zanieb authored Aug 13, 2024
1 parent ef94861 commit e8876ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
20 changes: 6 additions & 14 deletions docs/concepts/python-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,6 @@ To exclude downloads and only show installed Python versions:
$ uv python list --only-installed
```

## Discovery of virtual environments

Some uv commands may use a Python interpreter from a virtual environment. When searching for virtual
environments, uv prioritizes (in order):

- The `VIRTUAL_ENV` environment variable.
- The `CONDA_PREFIX` environment variable.
- A `.venv` directory in the working directory.
- A `.venv` directory in any parent directory.

After exhausting these possibilities, uv will either
[search for a Python installation](#discovery-of-python-versions) or exit with an error if the
command requires a virtual environment.

## Discovery of Python versions

When searching for a Python version, the following locations are checked:
Expand All @@ -158,6 +144,12 @@ When searching for a Python version, the following locations are checked:
- On Windows, the Python interpreter returned by `py --list-paths` that matches the requested
version.

In some cases, uv allows using a Python version from a virtual environment. In this case, the
virtual environment's interpreter will be checked for compatibility with the request before
searching for an installation as described above. See the
[pip-compatible virtual environment discovery](../pip/environments.md#discovery-of-python-environments)
documentation for details.

When performing discovery, non-executable files will be ignored. Each discovered executable is
queried for metadata to ensure it meets the [requested Python version](#requesting-a-version). If
the query fails, the executable will be skipped. If the executable satisfies the request, it is used
Expand Down
21 changes: 6 additions & 15 deletions docs/pip/environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,9 @@ will search for a virtual environment in the following order:
If no virtual environment is found, uv will prompt the user to create one in the current directory
via `uv venv`.

If the `--system` flag is included, uv will skip virtual environments and search for:

- The Python interpreter available as `python3` on macOS and Linux, or `python.exe` on Windows.
- On Windows, the Python interpreter returned by `py --list-paths` that matches the requested
version.

If a specific Python version is requested, e.g., `--python 3.7`, additional executable names are
included:

- The Python interpreter available as, e.g., `python3.7` on macOS and Linux.

When running a command that does not mutate the environment such as `uv pip compile`, uv does not
_require_ a virtual environment. Instead, it needs a Python toolchain to create ephemeral
environments. See the documentation on
[toolchain discovery](../concepts/python-versions.md#discovery-order) for details on discovery.
If the `--system` flag is included, uv will skip virtual environments search for an installed Python
version. Similarly, when running a command that does not mutate the environment such as
`uv pip compile`, uv does not _require_ a virtual environment — however, a Python interpreter is
still required. See the documentation on
[Python discovery](../concepts/python-versions.md#discovery-order) for details on the discovery of
installed Python versions.

0 comments on commit e8876ad

Please sign in to comment.