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

Fix: find libpython for venvs created by uv #1678

Merged
merged 1 commit into from
Oct 7, 2024
Merged

Conversation

t-kalinowski
Copy link
Member

This allows using reticulate with a venv created with uv.

Reported in #1669 (comment)

Tested interactively with:

uv <- function(...) {
  reticulate:::system2t("uv", paste(c(...), collapse = " "))
}

uv_install <- function(..., python = py_exe()) {
  uv("pip install",
     "--python", shQuote(python),
     c(...))
}

uv_venv_create <- function(envname = NULL, python_version = "3.11",
                           packages = "numpy", ..., force = FALSE) {
  path <- path.expand(reticulate:::virtualenv_path(envname))
  if (force)
    unlink(path, recursive = TRUE, force = TRUE)
  dir.create(path, showWarnings = FALSE, recursive = TRUE)

  uv(
    "venv",
    "--no-project",
    "--seed",
    "--no-config",
    "--python-preference only-managed",
    "--python", python_version,
    ...,
    shQuote(path)
  )

  if (length(packages))
    uv_install(packages, python = reticulate:::virtualenv_python(path))

  invisible(path)
}

uv_venv_create(
  force = TRUE,
  packages = c(
    "docutils",
    "pandas",
    "scipy",
    "matplotlib",
    "ipython",
    "tabulate",
    "plotly",
    "psutil",
    "kaleido",
    "wrapt"
  )
)

All reticulate tests pass except for one, which precipitated upstream PR astral-sh/uv#7978.

@t-kalinowski t-kalinowski mentioned this pull request Oct 7, 2024
@t-kalinowski t-kalinowski merged commit e3c508b into main Oct 7, 2024
16 checks passed
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

Successfully merging this pull request may close these issues.

1 participant