astral-sh / uv

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

Bundle Python Interpreter in virtual environments #7865

Open Turakar opened 1 month ago

Turakar commented 1 month ago

For system wide installations of applications build with uv, it would be nice to have an option to build an execution environment which is self contained and does not rely on the user's local files (~/.local/share/uv). My usecase for this would be an application that I want to install to a server for system-wide usage. At the moment, you can achieve this with the following commands (with some path adjustments):

uv venv --no-cache
uv pip install --no-cache -r requirements.lock
cp -r ~/.local/share/uv/python/cpython-3.12.5-linux-x86_64-gnu python
rm .venv/bin/python
ln -s python/bin/python3.12 .venv/bin/python

# To run the program
.venv/bin/python <your script.py>

I.e., you can replace the symlinked python interpreter by a bundled copy.

I am not entirely sure how this should be implemented. In a first simple step, one could add a --bundle-python flag to uv venv which copies the downloaded Python interpreter to, e.g., .venv/python and uses it instead of a path in ~/.local/share/uv.

However, you can take this idea further, up to a uv install command which would do something similar to make install.

Turakar commented 1 month ago

Ok, you can kinda do this already by passing UV_PYTHON_INSTALL_DIR (docs) to uv venv.

zanieb commented 1 month ago

I think we want to add this feature.

zanieb commented 1 month ago

Related

danielgafni commented 1 month ago

Ohh til UV_PYTHON_INSTALL_DIR exists.

I was looking for this parameter in CLI --help and it's not mentioned there.

Perhaps

  1. The env var should be mentioned in uv python * docs
  2. uv python install * commands should take an --install-dir argument?
zanieb commented 1 month ago

Yes we should mention it in the help documentation. I'd also be down to accept a target directory in the CLI.

danielgafni commented 1 month ago

Ok, I started working on this in #7920. Does --install-dir name work?