-
Notifications
You must be signed in to change notification settings - Fork 164
Description
Recently I have been investigating best practices for deploying reticulated content to Posit Connect. One of the things I have been trying to decide on is the best way to create virtual environments that are used by Reticulate and Renv.
Reticulate has the reticulate::virtualenv_create function:
reticulate::virtualenv_create(envname = "./.venv", python = "3.11")What I like about reticulate::virtualenv_create Is that it will do a good job finding a Python interpreter in your system that matches your request. In my example above, any Python interpreter using 3.11.
Renv has a similar function renv::use_python. When I pass only the major and minor version of Python, it fails to find an interpreter.
> system2("ls", "-la /opt/python")
total 0
drwxr-xr-x. 1 root root 51 Oct 17 17:18 .
drwxr-xr-x. 1 root root 20 Oct 17 17:18 ..
drwxr-xr-x. 1 root root 41 Oct 17 17:15 3.11.13
drwxr-xr-x. 1 root root 41 Oct 17 17:15 3.12.11
lrwxrwxrwx. 1 root root 19 Oct 17 17:16 default -> /opt/python/3.12.11
drwxr-xr-x. 7 root root 98 Oct 17 17:19 jupyter
> renv::use_python(python = "3.11", name = "./.venv")
Error: '3.11' does not refer to a valid python interpreterIf I pass the absolute path to the Python interpreter, it works as desired.
> renv::use_python(python = "/opt/python/3.11.13/bin/python", name = "./.venv")
- Creating virtual environment '.venv' ... Done!
- Updating Python packages ... Done!
- Lockfile written to "~/tmp/ret-test/renv.lock".
- Activated Python 3.11.13 [virtualenv; .venv]Would it be possible to change the renv::use_python function so that with only passing the major or minor Python version, it can discover the interpreter to create the virtual environment with?