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

Bundle Python Interpreter in virtual environments #7865

Open
Turakar opened this issue Oct 2, 2024 · 8 comments
Open

Bundle Python Interpreter in virtual environments #7865

Turakar opened this issue Oct 2, 2024 · 8 comments
Labels
enhancement New feature or improvement to existing functionality

Comments

@Turakar
Copy link

Turakar commented Oct 2, 2024

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
Copy link
Author

Turakar commented Oct 2, 2024

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

@Turakar Turakar closed this as completed Oct 2, 2024
@zanieb zanieb reopened this Oct 2, 2024
@zanieb zanieb changed the title Bundle Python Interpreter Bundle Python Interpreter in virtual environments Oct 2, 2024
@zanieb
Copy link
Member

zanieb commented Oct 2, 2024

I think we want to add this feature.

@zanieb zanieb added the enhancement New feature or improvement to existing functionality label Oct 2, 2024
@zanieb
Copy link
Member

zanieb commented Oct 2, 2024

@danielgafni
Copy link
Contributor

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
Copy link
Member

zanieb commented Oct 2, 2024

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

@danielgafni
Copy link
Contributor

danielgafni commented Oct 4, 2024

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

@alexwilson1
Copy link

Bundling Python into .venv using UV_PYTHON_INSTALL_DIR does not work because when .venv is not empty (contains Python) the installation gives this error:

error: Project virtual environment directory cannot be used because it is not a compatible environment but cannot be recreated because it is not a virtual environment

--bundle-python would be ideal

@ginkgo97
Copy link

ginkgo97 commented Feb 4, 2025

Will the option --install-dir or the env UV_PYTHON_INSTALL_DIR be able to be configured in uv.toml?

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

No branches or pull requests

5 participants