-
Notifications
You must be signed in to change notification settings - Fork 335
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
Issue with reticulate::py_module_available("rdkit") returning TRUE in RStudio Console but FALSE in Shiny Server.R #1757
Comments
What does Most likely, a different Python installation is being used, either due to a different working directory, or different environment variables. Consulting the Order of Discovery might be helpful |
Thank you very much for responding RStudio console: NOTE: Python version was forced by use_python() function
Shiny server.R NOTE: Python version was forced by use_python() function
Interestingly if I take two step approach and run reticulate::py_module_available("rdkit") in console first and then open shiny app, reticulate::py_module_available("rdkit") (from shiny server.R) prints TRUE |
Where is module <- import("rdkit")
py_repr(module)
py_get_attr(module, "__path__")
py_get_attr(module, "__file__") |
|
I think this is a hint that the seemingly identical Try this. In the shiny app, at the first location where python is initialized by the shiny app: tryCatch(import("rdkit"), error = function(e) {
print(py_config())
stop(e)
}) |
Thank you very much for your patience ;) thats what I am getting: python: /usr/local/bin/python3.12 NOTE: Python version was forced by use_python() function |
Can you provide an MRE? It could be a binary incompatibility between rdkit and something in the shiny app, where loading the app causes R to load a dll that then prevents rdkit from loading correctly. We've observed that before between Is pre-loading Python + rdkit before loading shiny an option? |
While creating the MRE, I noticed that print(reticulate::py_module_available("rdkit")) returned TRUE on the server, regardless of whether it was run before or after loading Shiny or other libraries. The app (actual one which was failing) includes a .py file, though it's not explicitly sourced using reticulate::source_python(). Coincidentally, I had named this file rdkit.py, which seemingly conflicted with the library name. Renaming the file resolved the issue. I also observed that the pycache folder was created when RDKit wasn't found, but after renaming the file, it no longer appeared. |
Seems like you were masking the installed Thanks for reporting back and closing the loop! |
I'm encountering strange behavior using the reticulate package in R. When I run the following in the RStudio console:
reticulate::py_module_available("rdkit")
It returns TRUE, but when I include the same code at the top of my server.R in a Shiny app, run the app, it prints FALSE.
However, if I first run reticulate::py_module_available("rdkit") in the R console and then start the Shiny app, the code inside Shiny prints TRUE as expected. But if I start a fresh Shiny session, it prints FALSE.
Interestingly, for other modules like matplotlib, I don’t see this issue: both in the console and inside the Shiny app, reticulate::py_module_available("matplotlib") returns TRUE.
I also verified that both libraries (rdkit and matplotlib) are located in the same directory.
Has anyone encountered this issue or know why rdkit behaves differently in a Shiny app compared to the R console?
Many thanks in advance
Bachi
The text was updated successfully, but these errors were encountered: