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

Support for uv #1669

Open
t-kalinowski opened this issue Sep 16, 2024 · 3 comments
Open

Support for uv #1669

t-kalinowski opened this issue Sep 16, 2024 · 3 comments

Comments

@t-kalinowski
Copy link
Member

uv is a fast and efficient package management tool. We should consider adding support for it in reticulate.

One of its key advantages is that it allows for installing a specific Python version on demand in the same motion as setting up the virtual environment. This capability eliminates the need for users to first ensure a suitable Python venv starter is pre-installed (e.g., by running install_python()). It also avoids the need for reticulate to search for and locate suitable virtualenv_starter()s. This feature could streamline the user experience.

The ability to install a specific Python version on demand means that uv could serve as a drop-in replacement for many uses of conda. Importantly, it sidesteps the potential risk of binary incompatibilities that conda usage introduces.

@vincentarelbundock
Copy link

I would also be very interested in this feature. uv has taken the Python world by storm, and has become incredibly popular in a short amount of time.

I believe that the main stumbling is that reticulate does not detect the location of libpython.

In this minimal example, I install uv, create a new project, and then call reticulate::py_discover_config() in R. There are two different calls:

  1. Rscript without preamble uses the default Python install on my machine.
  2. Rscript with a uv run preamble uses the virtual environment and python install set up by uv.

Notice that we get [NOT FOUND] for libpython in the second case.

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Initialize a new project
uv init mwe
cd mwe

# Add some python dependencies
uv add pandas

default reticulate python config

Rscript -e "reticulate::py_discover_config()"

python:         /home/username/.virtualenvs/global/bin/python
libpython:      /home/username/.pyenv/versions/3.12.4/lib/libpython3.12.dylib
pythonhome:     /home/username/.virtualenvs/global:/home/username/.virtualenvs/global
virtualenv:     /home/username/.virtualenvs/global/bin/activate_this.py
version:        3.12.4 (main, Jun  9 2024, 13:30:56) [Clang 15.0.0 (clang-1500.3.9.4)]
numpy:          /home/username/.virtualenvs/global/lib/python3.12/site-packages/numpy
numpy_version:  2.0.2

uv reticulate python config

uv run Rscript -e "reticulate::py_discover_config()"

python:         /home/username/mwe/.venv/bin/python
libpython:      [NOT FOUND]
pythonhome:     /home/username/mwe/.venv:/home/username/mwe/.venv
virtualenv:     /home/username/mwe/.venv/bin/activate_this.py
version:        3.12.6 (main, Sep  9 2024, 21:36:32) [Clang 18.1.8 ]
numpy:          /home/username/mwe/.venv/lib/python3.12/site-packages/numpy
numpy_version:  2.1.2

@t-kalinowski
Copy link
Member Author

@vincentarelbundock Thanks for reporting this! Reticulate should now work with a venv created by uv after #1678.

I'll keep this issue open since we'd still like to add convenient wrappers in reticulate around uv, similar to the existing conda_* and virtualenv_* functions.

@vincentarelbundock
Copy link

Thanks a lot for the quick fix @t-kalinowski . Looks like the dev version is working for me!

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

No branches or pull requests

2 participants