Invalid version specification on Shiny app

不想你离开。 提交于 2021-02-07 10:41:14

问题


When I try to deploy my (reticulate-powered) Shiny app to shinyapps.io, I get the following error:

Error in value[[3L]](cond) : invalid version specification ‘20.1b1’
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

While it is not explicit, I suppose the error is refering to the pip version, which I never explicitly specify.

This is the part of the code that precedes the ui and server functions:

library(reticulate)
library(shiny)

virtualenv_create(envname = "elicit", python="python3")
virtualenv_install("elicit", packages = c('numpy', 'Gpy'))
use_virtualenv("elicit", required = TRUE)

When I comment this out together with any Python-related code from the UI and the server, everything works fine.

How can I set the valid version the site is requesting? I see that reticulate::virtualenv has a pip_options argument, but I can't find useful documentation about how to use it.

I am also not very proficient at setting virtual and conda environments, so I could very well be missing some basic step.

Update

I noticed that if I switch the order of the use_virtualenv and the virtualenv_install calls I get a different error:

ERROR: The requested version of Python
('~/.virtualenvs/elicit/bin/python') cannot be used, as another version
of Python ('/usr/bin/python3') has already been initialized. Please
restart the R session if you need to attach reticulate to a different
version of Python.
Error in value[[3L]](cond) : 
  failed to initialize requested version of Python
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

I've tried everything I could think of but I can't get that fixed either.


回答1:


I actually found a solution for this issue. Since the bugged version of pip gets installed as soon as your create the virtualenv, I forcibly uninstalled it and then installed the version that worked when I built my app. Here is the code that I used:

virtualenv_create(envname = "python_environment", python = "python3")
virtualenv_remove(envname = "python_environment", packages = "pip")
virtualenv_install(envname = "python_environment", packages = c("pip==19.0.3","numpy","nltk","torch"), ignore_installed = TRUE)
use_virtualenv("python_environment", required = TRUE)



回答2:


I wrote this as a comment to the accepted answer, but I'm also posting this as an answer for better visibility and further explanation.

What worked in the end for my case was creating a .Rprofile file containing the following line:

Sys.setenv(RETICULATE_PYTHON = "~/.virtualenvs/elicit/bin/python3")

That file should be located in the same folder as app.R and should be deployed to the remote server. The final app.R file looks just like the one posted in the question.


Update: This eventually broke again, and what fixed it for me was to remove and reinstall pip (as pointed out by theThalamus), but without specifying a pip version. So app.R would look something like this:

virtualenv_create(...)  # create virtual environment
virtualenv_remove(envname = "python_environment", packages = "pip")
virtualenv_install(envname = "python_environment", packages = "pip")
virtualenv_install(...)  # install other packages

The two virtualenv_install instances can probably be merged, but I decided to keep them separate to highlight the fix.



来源:https://stackoverflow.com/questions/61361954/invalid-version-specification-on-shiny-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!