uv/docs/guides/install-python.md
Charlie Marsh e61a221fef
Migrate from MdBook to MkDocs (#5062)
## Summary

We want to have consistency between the Ruff and uv documentation for
the upcoming release. We don't love the Ruff docs, but we'd rather have
consistency and then work towards improving them both, rather than have
two very-different documentation sites that both have weaknesses.

The setup here is simpler than in Ruff as: (1) we don't yet generate any
docs from Rust and (2) we don't try to reuse the README in the uv
documentation (which adds a lot of complexity in Ruff). So the change
here is mostly a 1-to-1 port to MkDocs.

## Test Plan

![Screenshot 2024-07-14 at 9 49
15 PM](https://github.com/user-attachments/assets/8bfb5b06-08ff-4329-b368-d9087b78996e)
2024-07-15 22:22:07 +00:00

65 lines
2.3 KiB
Markdown

# Installing Python
uv can manage Python installations — Python does not need to be installed to use uv.
To install Python:
```console
$ uv python install
```
This will install a uv-managed Python version even if there is already a Python installation on the system.
Once Python is installed, it can be invoked via `python`:
```console
$ python --version
```
To prevent uv from managing Python system-wide, provide the `--no-shim` option during installation.
## Installing a specific version
To install a specific Python version:
```console
$ uv python install 3.12
```
See the [Python versions](../python-versions.md) documentation for more details.
## Viewing Python installations
To view available and installed Python versions:
```console
$ uv python list
```
See the [`python list`](../python-versions.md#viewing-available-python-versions) documentation for more details.
<!--TODO(zanieb): The above should probably link to a CLI reference and that content should be moved out of that file -->
## Automatic Python downloads
Note that Python does not need to be explicitly installed to use uv. By default, uv will automatically download Python versions when they are required. For example, the following would download Python 3.12 if it was not installed:
```console
$ uv run --python 3.12 python -c 'print("hello world")'
```
Even if a specific Python version is not requested, uv will download the latest version on demand. For example, the following will create a new virtual environment and download a managed Python version if one hasn't been installed yet:
```console
$ uv venv --python-preference only-managed
```
Note that when an automatic Python installation occurs, the `python` command will not be added to the shell. Use `uv python install-shim` to ensure the `python` shim is installed.
## Using an existing Python installation
uv will also use an existing Python installation if already present on the system. There's no configuration necessary for this behavior, uv will use the system Python if it satisfies the requirements of the command invocation.
To force uv to use the system Python, provide the `--python-preference only-system` option.
See the [Python version preference](../python-versions.md#adjusting-python-version-preferences) documentation for more details.