I am creating an app in Shiny using R. I have a model in python that I am using in the app so I use the reticulate package to run it and a virtual environment in the same folder as the app to access python3. It works great locally, but once I deploy it I get an error in the logs that says
venv/bin/python: Permission denied
(venv is my virtual env).
I have tried adding an .Rprofile file (to the folder with the app) that includes source venv/bin/activate . Also, in case it is helpful, the Python component uses the keras package. I have also downloaded all of the necessary packages into my virtual environment.
I also ran use_python("venv/bin/python", required = TRUE) instead of reticulate::use_virtualenv("venv", required = TRUE) which also works locally, but I get the same error described above once I deploy it.
I'm trying to deploy to the shinyapps.io site. I'm not sure how to check or ensure that the virtual environment is available there except including it in my upload which I am doing.
This path doesn't exist on the shinyapps.io server, and after creating your python environment (which is empty) I suspect you have to explicitley install all the python libraries that you want to use e.g. py_install(c('pandas', 'matplotlib'))
though it does make sense to need to install all of the libraries I want. I was working on that using virtualenv_install(envname, packages, ignore_installed = FALSE) but will try py_install(c('pandas', 'matplotlib')). Thanks!
You are probably right with this virtualenv_install(envname, packages, ignore_installed = FALSE) I have never had the need to use python virtual environments before.
I tried it and py_install() works too! Now the problem is that even though it recognizes that I want it to use python3 it seems like it's still using python2 which my code won't work with
Please share this setup section of your code to have a better idea of what is going on.
Up until now you have created the virtual environment and installed your libraries but you are not telling reticulate to use the virtual environment, try with something like this use_virtualenv("python_environment")
so I unfortunately do already have a use_virtualenv() line.
@Yarnabrina excellent suggestion but I think use_python requires a path to something stored on my computer which has been part of the problem so far. Let me know if you know of any way to just specify the python version though. Thank you!
I tried using virtualenv_install() instead of py_install() and now it works! Thank you both so much for your help @andresrcs and @Yarnabrina!
If others come across this with the same problem, here is the relevant code to set up the python virtual environment to be able to deploy to shinyapps.io:
For clarity, the specific packages are just what my python code needed.
Also, you may need to run (and then comment out for deployment) the following line to use an older version of rsconnect if you get an error that says: reticulate is in use, but python was not specified