-
Notifications
You must be signed in to change notification settings - Fork 326
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 --user
option in pip_install()
#1506
Comments
I would strongly encourage working in a virtual environment whenever possible. Installing Python packages into a user library with virtualenv_create("r-reticulate")
py_install(packages = c("scipy"),
envname = "r-reticulate") That said, if you find yourself working on a machine with draconian restrictions that prevent you from creating or using a Python virtual environment, you can override the default by explicitly passing an argument py_install("scipy", pip_options = "--user") |
Yes, agreed on using a virtual environment wherever possible. I anticipate that some of these restrictions will be relaxed a bit more in the future as the latest versions of python become more prevalent. I have been working towards getting everything switched over to use a virtualenv preferentially. Other than the current issue with CRAN reticulate and I am aware of the problems with a general user level library and/or breaking system package installs... But in these "draconian" cases, venvs would be likely need to be installed by a special method, or allow-listed by name, due to the way executable permissions get handled. Thanks for your consideration and the tip about |
Hi, actually with reticulate 1.34.0 in this case I get: reticulate::py_install("scipy", pip_options="--user")
#> Using Python: C:/Program Files/Python311/python.exe
#> Creating virtual environment "~/.virtualenvs/r-reticulate" ...
#> + "C:/Program Files/Python311/python.exe" -m venv "C:/Users/Andrew.G.Brown/.virtualenvs/r-reticulate"
#> FAILED
#> Error: Error creating virtual environment '~/.virtualenvs/r-reticulate' [error code 1]
Whereas this works: system(paste(shQuote("C:/Program Files/Python311/python.exe"), "-m pip install --upgrade --user scipy"))
#> Requirement already satisfied: scipy in c:\users\andrew.g.brown\appdata\roaming\python\python311\site-packages (1.11.4)
#> Requirement already satisfied: numpy<1.28.0,>=1.21.6 in #> c:\users\andrew.g.brown\appdata\roaming\python\python311\site-packages (from scipy) (1.26.2) Is there some trick to prevent the virtualenv from being created, or otherwise safely skipping over it and falling back to system if/when it fails? |
Unfortunatly, This sounds like a somewhat speciality use-case, I would recommend making a custom wrapper like: py_install_user_base <- function(..., python = Sys.which("python3")) {
system2(python, c("-m pip install --user", ...))
} |
That is unfortunate. I understand In making design decisions that are "opinionated" we can sometimes prevent users from going down the wrong path. There is the idea we should have only one "right" way to do things and it should be "obvious"--I would say this reasoning is why a wrapper function like Recent design decisions in reticulate are based on a well-intentioned, but generally incorrect, idea that users are able to create virtual environments, control their contents, and execute the binaries in them. I note that I don't believe there is anything exotic about users without permissions to install their own executables; this is very common situation in industries that are not primarily focused on developing software.. I would suggest an error message in the example above RE: virtualenv creation failing. Also, since there are cases where no amount of installing python, setting up environments etc. will help, I would suggest a method to "opt in" and bypass common sources failure like site packages not being writable. I think you should reconsider that such an option would be out of scope for reticulate--for a package that is the interface to Python in R I think there should be a (non-default) way to use the system python similarly to a venv. There may need to be sidebars or warnings but it should be possible.
I have workarounds in a couple of my reticulate based packages to construct system calls... If I must maintain some extra logic in lieu of reticulate to provide a similar environment setup for all users then so be it. Thanks for your consideration. |
On some systems the system python site-packages is not writeable. Often there are limitations on creation/execution of binaries in user-created conda or virtual environments. Sometimes the system python, or python the user can run, is an installation associated with another program with or without a conda or virtual environment associated. The user running
install_python()
themselves is generally not an option under these conditions--Python can be installed but not executed.In the past when using
reticulate::py_install()
or related, it would have pip to fall back to a user installation with message"Defaulting to user installation because normal site-packages is not writeable"
I see that in 1.27
--no-user
was made default in the command string, and then an internal argumentno_user
was added topip_install()
to toggle it for old versions ofpip
.reticulate/R/pip.R
Lines 31 to 33 in 5d0a9a5
Would it be possible to optionally add
--user
flag to get around errors like the one below, exposing it as a user-level argument to e.g.py_install()
? Perhaps there is a more elegant way to do what I am trying to do, in terms of bootstrapping existing python installations, and getting the dependencies installed as seamlessly for the user as possibleIn above example, I use a command directly in a windows prompt, but the same message is generated by standard calls to
py_install()
Note the error message suggests the use of --user flag:
"Consider using the
--useroption or check the permissions."
I think
--no-user
is a fine default, but I think there are legitimate use cases that rely on--user
. Often a solution to fix the failed reticulate install is to drop to the command line / system call and do the suggested command that failed, with --user flag replacing --no-user.The text was updated successfully, but these errors were encountered: