Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python -m uv no longer installs to the python specified (if prerelease) #7417

Closed
hauntsaninja opened this issue Sep 16, 2024 · 6 comments · Fixed by #7440
Closed

python -m uv no longer installs to the python specified (if prerelease) #7417

hauntsaninja opened this issue Sep 16, 2024 · 6 comments · Fixed by #7440
Assignees
Labels
bug Something isn't working

Comments

@hauntsaninja
Copy link
Contributor

hauntsaninja commented Sep 16, 2024

I think this is from #7300 cc @zanieb

Using the python -m uv / python3.13 -m uv form should count as opt-in here?
Came up in https://github.com/psf/black/actions/runs/10876175035/job/30175719632?pr=4453

Setup:

λ docker run --rm -it python:3.13.0rc2 sh
Unable to find image 'python:3.13.0rc2' locally
3.13.0rc2: Pulling from library/python
56c9b9253ff9: Pull complete 
364d19f59f69: Pull complete 
843b1d832182: Pull complete 
a348c2a8d946: Pull complete 
4e73bb8758d7: Pull complete 
38ea74b559d3: Pull complete 
ecad7386bb32: Pull complete 
Digest: sha256:b40565d2da0deec1e7ae3ba7e170376cbbf8d0a5a75b2a049a980193a196b81d
Status: Downloaded newer image for python:3.13.0rc2
# curl -LsSf https://astral.sh/uv/install.sh | sh
downloading uv 0.4.10 aarch64-unknown-linux-gnu
installing to /root/.cargo/bin
  uv
  uvx
everything's installed!

To add $HOME/.cargo/bin to your PATH, either restart your shell or run:

    source $HOME/.cargo/env (sh, bash, zsh)
    source $HOME/.cargo/env.fish (fish)
# . $HOME/.cargo/env
# uv --version
uv 0.4.10
# uv pip install --python $(which python) uv
Resolved 1 package in 182ms
Prepared 1 package in 238ms
Installed 1 package in 0.62ms
 + uv==0.4.10

Failure (that's a little confusing until you realise what's going on):

# python -m uv pip install --system pypyp 
error: The interpreter at /usr is externally managed, and indicates the following:

  To install Python packages system-wide, try apt install
  python3-xyz, where xyz is the package you are trying to
  install.

  If you wish to install a non-Debian-packaged Python package,
  create a virtual environment using python3 -m venv path/to/venv.
  Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
  sure you have python3-full installed.

  If you wish to install a non-Debian packaged Python application,
  it may be easiest to use pipx install xyz, which will manage a
  virtual environment for you. Make sure you have pipx installed.

  See /usr/share/doc/python3.11/README.venv for more information.

Consider creating a virtual environment with `uv venv`.

Success with uv 0.4.9

# uv pip install --python $(which python) 'uv<0.4.10'
Resolved 1 package in 61ms
Prepared 1 package in 246ms
Uninstalled 1 package in 0.30ms
Installed 1 package in 0.52ms
 - uv==0.4.10
 + uv==0.4.9

# python -m uv --version
uv 0.4.9
# python -m uv pip install --system pypyp 
Resolved 1 package in 66ms
Prepared 1 package in 20ms
Installed 1 package in 1ms
 + pypyp==1.2.0
@zanieb
Copy link
Member

zanieb commented Sep 16, 2024

@hauntsaninja I think this is because you use --system which opts out of using the current interpreter. Perhaps that's a bug if the current interpreter is not from a virtual environment?

@zanieb
Copy link
Member

zanieb commented Sep 16, 2024

Reproduced this with

❯ uv pip install --python /Users/zb/.local/share/uv/python/cpython-3.13.0rc2-macos-aarch64-none/bin/python3 uv --break-system-packages
Resolved 1 package in 235ms
Prepared 1 package in 767ms
Installed 1 package in 8ms
 + uv==0.4.10
❯ /Users/zb/.local/share/uv/python/cpython-3.13.0rc2-macos-aarch64-none/bin/python3 -m uv pip install --system -v httpx
DEBUG uv 0.4.10
DEBUG Searching for Python interpreter in system path
DEBUG Found `cpython-3.12.6-macos-aarch64-none` at `/opt/homebrew/bin/python3` (search path)
DEBUG Using Python 3.12.6 environment at /opt/homebrew/opt/[email protected]/bin/python3.12

@zanieb
Copy link
Member

zanieb commented Sep 16, 2024

And this is because of the implementation here

let from_environments = python_executables_from_environments();
let from_installed = python_executables_from_installed(version, implementation, preference);
match environments {
EnvironmentPreference::OnlyVirtual => Box::new(from_environments),
EnvironmentPreference::ExplicitSystem | EnvironmentPreference::Any => {
Box::new(from_environments.chain(from_installed))
}
EnvironmentPreference::OnlySystem => Box::new(from_installed),
}

@zanieb
Copy link
Member

zanieb commented Sep 16, 2024

Considering this a bug and fixing at #7440

@hauntsaninja
Copy link
Contributor Author

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants