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

Allow creating a python shim on python install #6265

Open
zanieb opened this issue Aug 20, 2024 · 7 comments
Open

Allow creating a python shim on python install #6265

zanieb opened this issue Aug 20, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@zanieb
Copy link
Member

zanieb commented Aug 20, 2024

When installing Python, I should be able to opt-in to adding a python shim to my PATH.

@zanieb zanieb added the enhancement New feature or request label Aug 20, 2024
@ophiry
Copy link

ophiry commented Aug 23, 2024

not sure this was the original intention, but if the shim will work the same as uv run (in terms of environment resolution) it would be very useful

this will allow simpler integration with IDEs

(instead of explicitly providing a venv, they could be pointed to the uv shim that will do the environment resolution)

@tux-type
Copy link

This would be very useful, and is also what is missing in uv compared to pyenv.

@zanieb
Copy link
Member Author

zanieb commented Aug 26, 2024

Please just 👍 the original post if you want this. If you have commentary on the implementation or behavior of the shim, that's totally welcome but let's keep the noise down for those subscribing to updates.

not sure this was the original intention, but if the shim will work the same as uv run (in terms of environment resolution) it would be very useful

We don't think we can do this by default because people have specific expectations about python behavior but I think an opt-in mode makes sense.

@pietrodn
Copy link

pietrodn commented Sep 8, 2024

This would be a great improvement for the entire Python ecosystem user-friendliness. Currently we manage Python projects like this where I work:

  1. Install pyenv.
  2. Install Python versions from source, compiling them (this is a huge pain especially for nontechnical users which get stuck with environment issues and compilation errors).
  3. Use Poetry which automatically detects the correct Python version from the constraint in pyproject.toml.

Having uv install binary version of Python with pyenv-style shims would allow us to entirely drop pyenv and remove the burden of compiling Python from the users... even if we don't switch to uv for package management. 😄

@tats-u
Copy link

tats-u commented Sep 23, 2024

I want to migrate from rye to uv, but the migration is blocked by this issue.
This feature is especially wanted by Windows users because Windows doesn't bundle Python.
If you run python command without a global Python, an annoying Microsoft Store window is launched.

@pietrodn
Copy link

I am currently using this workaround to expose uv's Pythons to my shell's PATH:

for dir in $(uv python dir)/*/bin; do PYTHON_PATHS="$dir:$PYTHON_PATHS"; done
export PATH="$PYTHON_PATHS:$PATH"

The problem is that there are multiple python3.10, python3.11, ... executables, only one version for each minor would be exposed. But I typically pick only one version for each Python minor version.

@vivienm
Copy link
Contributor

vivienm commented Sep 23, 2024

As a workaround, I wrote the following script python3.x:

#!/usr/bin/env bash
set -euo pipefail

SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"

if [[ "${SCRIPT_NAME}" =~ ^python3\.[0-9]+$ ]]; then
  PYTHON_VERSION="${SCRIPT_NAME#python}"
else
  2>&1 echo "Error: Invalid script name: ${SCRIPT_NAME}"
  exit 1
fi

exec uv run --no-project --python "${PYTHON_VERSION}" --python-preference only-managed --no-config python "$@"

And I have symlinks python3.x pointing to this script:

~/.local/bin/python3.8  -> ~/.local/share/python3.x
~/.local/bin/python3.9  -> ~/.local/share/python3.x
~/.local/bin/python3.10 -> ~/.local/share/python3.x
~/.local/bin/python3.11 -> ~/.local/share/python3.x
~/.local/bin/python3.12 -> ~/.local/share/python3.x

It's not great, but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants