astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
26.89k stars 782 forks source link

`uv venv ...` not recognizing system-installed python #9272

Closed birkin closed 51 minutes ago

birkin commented 3 hours ago

I'm trying to run the command:

uv venv ./venv_2024-11-20 --python 3.8 --native-tls --python-preference only-system

...to ensure I'm using a version of python already installed by our sys-admin. This yields the message:

× No interpreter found for Python 3.8 in search path

The system-version of python 3.8 I'm trying to install does exist an an /opt/local/... path. How can I pass its path to uv venv ... or otherwise make uv venv ... recognize this system-installed version?

FishAlchemist commented 3 hours ago

Is your Python located in the path specified by the PATH environment variable or the UV_PYTHON_INSTALL_DIR environment variable? https://docs.astral.sh/uv/concepts/python-versions/#discovery-of-python-versions

What is your uv version? And what is the result of uv python list?

birkin commented 1 hour ago

@FishAlchemist

no success yet...

Info:


Recently tried:

Thanks for your response, though; willing to try other things!

FishAlchemist commented 1 hour ago

@birkin If there is no need to specify the installation path for the hosted Python, there is no need to specify UV_PYTHON_INSTALL_DIR. UV_PYTHON_INSTALL_DIR: Specifies the directory for storing managed Python installations.

However, if UV cannot find Python in the PATH and you don't plan to add this Python to the PATH, then specify the direct path to the Python interpreter.

--python /opt/local/python3.8.10/bin/
  -p, --python <PYTHON>                        The Python interpreter to use for the virtual environment. [env: UV_PYTHON=]
birkin commented 51 minutes ago

@FishAlchemist -- Thanks; passing that path works! That must be in the documentation, but I'd missed it, so much appreciated. I'll close this issue.

For reference, this works:

uv venv ./venv_2024-11-20 --python "/opt/local/python3.8.10/bin/python3" --native-tls --python-preference only-system
zanieb commented 48 minutes ago

Just to clarify, UV_PYTHON_INSTALL_DIR is where we install Python distributions to — we won't discover interpreters we do not manage in that directory.

It sounds like /opt/local/python3.8.10/bin/ isn't on your PATH. Specifying it manually is totally reasonable too though.

It's documented at https://docs.astral.sh/uv/concepts/python-versions/#requesting-a-version