Closed newne closed 2 months ago
As for the solution to this problem, adding python-preference
and setting its value to something other than only-system
should do the trick.
e.g.
uv venv -p 3.10.14 --python-preference installed
Although I tested this on Windows, I used the same solution to resolve the issue of not being able to create a virtual environment using managed installation on Ubuntu.
--python-preference <PYTHON_PREFERENCE>
Whether to prefer using Python installations that are already present on the system, or those that are downloaded and installed by uv
Possible values:
- only-managed: Only use managed Python installations; never use system Python installations
- installed: Prefer installed Python installations, only download managed Python installations if no system Python installation is found
- managed: Prefer managed Python installations over system Python installations, even if fetching is required
- system: Prefer system Python installations over managed Python installations
- only-system: Only use system Python installations; never use managed Python installations
According to the document, the default value of python-preference should be installed
. However, the actual result seems to be inconsistent with the documentation.
https://github.com/astral-sh/uv/blob/c0d3da8b6ae134036b3ed024762b08c4fb9f967b/docs/settings.md#python-preference--python-preference-
For more information about this flag, you might need to ask the programmer who wrote UV. I've only submitted document modifications.
❯ uv python list --only-installed
warning: `uv python list` is experimental and may change without warning
cpython-3.12.4-windows-x86_64-none C:\Users\user_name\AppData\Local\Programs\Python\Python312\python.exe
cpython-3.11.9-windows-x86_64-none C:\Users\user_name\AppData\Local\Programs\Python\Python311\python.exe
cpython-3.10.14-windows-x86_64-none C:\Users\user_name\AppData\Roaming\uv\data\python\cpython-3.10.14-windows-x86_64-none\install\python.exe
cpython-3.10.11-windows-x86_64-none C:\Users\user_name\AppData\Local\Programs\Python\Python310\python.exe
cpython-3.9.19-windows-x86_64-none C:\Users\user_name\AppData\Roaming\uv\data\python\cpython-3.9.19-windows-x86_64-none\python.exe
# ----------------------------------------
❯ uv venv -p 3.10.14 --python-preference only-managed
Using Python 3.10.14
Creating virtualenv at: .venv
Activate with: .venv\Scripts\activate
# ----------------------------------------
❯ uv venv -p 3.10.14 --python-preference installed
Using Python 3.10.14
Creating virtualenv at: .venv
Activate with: .venv\Scripts\activate
# ----------------------------------------
❯ uv venv -p 3.10.14 --python-preference managed
Using Python 3.10.14
Creating virtualenv at: .venv
Activate with: .venv\Scripts\activate
# ----------------------------------------
❯ uv venv -p 3.10.14 --python-preference system
Using Python 3.10.14
Creating virtualenv at: .venv
Activate with: .venv\Scripts\activate
# ----------------------------------------
❯ uv venv -p 3.10.14 --python-preference only-system
× No interpreter found for Python 3.10.14 in system path or `py` launcher
# ----------------------------------------
❯ uv venv -p 3.10.14
× No interpreter found for Python 3.10.14 in system path or `py` launcher
\cc @zanieb @konstin
Using managed interpreters with uv venv
requires the --preview
flag right now. We'll change this soon to match the behavior of all the preview commands (like uv python install
).
This should be resolved now.
Here is the problem: