Unable to import owlready2 module in shinyapps.io server

Hi,

When we import the package owlready2 , we get an error Error in py_module_import: ImportError: No module named owlready2" in the shinyapps,io server.... where as in our local system it works fine....can some one in shinyapps.io help us please?

Sincerely,
P.Srinivas Kumar

If you are using reticulate, you will need to include the command to install your python package in the code that is deployed to shinyapps.io, as it does not automatically happen.

2 Likes

Hi Josh,

Thank you for the reply....we have tried to install the package owlready2 using the command py_install(c("owlready2"))....and it gets installed in shiny apps.io...following is the content in the log file


Stored in directory: /home/shiny/.cache/pip/wheels/f2/7a/59/609ad5f3dcd6cec4b36db2c298359a25ff8f66d10d9adcf5fa
2018-11-29T09:54:43.790334+00:00 shinyapps[584773]: Successfully built owlready2
2018-11-29T09:54:43.797022+00:00 shinyapps[584773]: Installing collected packages: owlready2
2018-11-29T09:54:43.894055+00:00 shinyapps[584773]: Successfully installed owlready2-0.11
2018-11-29T09:54:43.987473+00:00 shinyapps[584773]: Installation complete.


however when we try to import the module owlready2 it gives the following error


Warning: Error in py_module_import: ImportError: No module named owlready2 2018-11-29T09:54:44.020059+00:00 shinyapps[584773]: 68: <Anonymous> 2018-11-29T09:54:44.020332+00:00 shinyapps[584773]: Error in py_module_import(module, convert = convert) : 2018-11-29T09:54:44.020333+00:00 shinyapps[584773]: ImportError: No module named owlready2


Also owlready2 need to be installed using python 3....

Kindly help us in resolving the issue...

If you require python 3, then when you configure reticulate with use_virtualenv you need to ensure you are specifying python 3.

Perhaps you could share a reproducible example that is just an app.R with you usage of reticulate and the attempt to import owlready2?

Hi Josh,
Thank you for the reply....Please find here with the code that we are trying to execute

library(shiny)
library(reticulate)
ui <- fluidPage(
      mainPanel(
         textOutput("text")
      )
   )

server <- function(input, output) {
  virtualenv_create("soilclassification")
  use_virtualenv("~/soilclassification")
  sys<-import("sys")
  print(sys$version)
  py_install(c('owlready2'))
  b<-import("owlready2")
  onto<-b$get_ontology("file://SoilClassification2.owl")
  onto$load()
  a$sync_reasoner()
  tt<-onto$Sample1$is_a
  output$text<-renderText({tt})
  
}


shinyApp(ui = ui, server = server)

We are not sure on how to configure virtual environment to use python 3 and then to import owlready2...

Kindly clarify

Sincerely,
Srinivas

From what I can see, reticulate's support for Python 3 is lacking at the moment.

I would suggest following along there, and adding your vote for improved support of Python 3, especially in environments where both Python 2 and 3 are present.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.