biolab / orange3

🍊 :bar_chart: :bulb: Orange: Interactive data analysis
https://orangedatamining.com
Other
4.89k stars 1.03k forks source link

Unable to deploy Orange model on Streamlit cloud #5688

Closed TonciG closed 3 years ago

TonciG commented 3 years ago

Hi,

I cannot deploy a Python web app, which uses previously built Orange3 model, on the Streamlit cloud.

The model is trained and tested in Orange3 (3.30.2) and then saved as .pkcls file. It is then used to make predictions as part of a webapp.py file built on top of Streamlit (1.1.0). This web app runs just fine on my PC. However, the problem arises when I try to deploy it on the Streamlit cloud.

From my investigations, it seems that the problem arises because my requirements.txt file (generated via pipreqs) lists Orange as version 2.7.8. This version cannot be found/installed by Streamlit server. When I change it to Orange3 == 3.30.2 then Streamlit finds it and installs it correctly. But then the problem arises when it tries to run my WebApp.py because it makes reference to Orange == 2.7.8 (via import Orange).

I would really appreciate your help.

Regards,

Tonci

markotoplak commented 3 years ago

Thanks for the report. How did you use pipreqs to generate your requirements file (so that we could at least reproduce the problem)? Why do you do it this way? I have no familiarity with anything like this.

Now that I think of your specific error, it might be caused because Orange3 uses Orange.* namespace; note the difference in 3; what you got was indeed the latest version of Orange2. This could mislead pipreqs/webapp if they try to automatically find dependencies. Can you instruct your tooling to specify source for Orange manually?

TonciG commented 3 years ago

Hi Marko,

Thank you on your quick reply.

I used pipreqs (version 0.4.10) from a virtual environment that also has the latest version of Orange and Streamlit. You use it via pipreqs ./

This generates the requirements.txt file, which says Orange==2.7.8.

Agree with you that the error is related to different versions of Orange (2.7.8 vs. 3.30.2). Via conda list I only get orange3 (3.30.2). But when I use pipreqs, it says Orange = 2.7.8.

Attached here you will find the requirements.txt and Python code for my web app.

requirements.txt webapp.txt

Tonci

markotoplak commented 3 years ago

So, at least for Orange, pipreqs does not work properly. This is not a problem of Orange, so I am closing this issue.

You will need to work around the problem somehow. Perhaps with modifying the requirements obtained as you wrote in your original post and then also modifying necessary parts of the web app (I do not understand where the problem is there and why it would link to another version).

You might also choose to fix pipreqs or other parts of your tooling or report the issue there.

TonciG commented 3 years ago

Hi Marko,

Even if I do not use pipreqs, the problem still remains, which is inability of Streamlit to build Orange dependencies.

According to instructions from Orange, to use Orange as part of a Python code we should import it as: import Orange. When I do that (no matter if I use pipreqs or write the requirements.text manually), then Streamlit looks for Orange ==2.7.8. On the other hand, if I change (manually) my requirements.txt to Orange3==3.30.2, then my Python web app no longer works. This is because import Orange3 cannot be used.

Any suggestions what could be done to fix this? You mentioned something about namespace.

Thanks,

Tonci

markotoplak commented 3 years ago

This is the problem of Streamlit cloud dependencies then - if it uses pipreqs internally, then I do not know what do to. Try to look for a workaround. If you've been following some instructions that use pipreqs then you will need to adapt accordingly.

Orange needs to be imported as import Orange, and installed as Orange3==3.30.2. If it works on your machine but not on the cloud server the problem is either configuration of your server app or there are bugs/limitations on the cloud server. I am not a user of Streamlit so I can not help you there.

TonciG commented 3 years ago

Hi Marko, Just so you know, I contacted Streamlit about the issue above. Still waiting for a response. Cheers, Tonci

markotoplak commented 3 years ago

Thanks for the report, and please report when you manage to solve your issue. I checked the instruction and saw there that if you wrote requirements.txt manually (specify correct Orange3==3.30.2) and make sure the platform used python3, this should not be an issue.

I do not know which repo you host there, but in https://github.com/TonciG/Telecom-Customer-Churn---Web-App/blob/main/requirements.txt the version is still wrong.

TonciG commented 3 years ago

Hi Marko, The repo you mentioned is the one that I use. I did try with Orange3==3.30.2 in my requirements file but it still does not work. Although Streamlit is able to use the correct version of Orange (3.30.2), my app no longer works as my .py code makes reference to Orange (via import Orange). No matter what I try, it does not work.

markotoplak commented 3 years ago

If Orange3 was indeed installed properly into your Streamlit environment, import Orange should work; it not having a "3" is not a problem. What is the error you see?

TonciG commented 3 years ago

From the log file attached (tried to launch it a minute ago), you will see that Orange3 is installed properly on Streamlit (after I change requirements.txt to Orange3==3.30.2). The problem arises just before the app is deployed on the web (see both the log file and figure below). As you can see import Orange is list as an error. logs-toncig-telecom-customer-churn---web-app-main-TCCWebApp.py-2021-11-11T12_00_34.593Z.txt Untitled

markotoplak commented 3 years ago

This error means that your installation of Orange worked fine. It is only that pyqt5 (one of Orange dependencies) needs some additional system libraries for it to work. See https://docs.streamlit.io/streamlit-cloud/get-started/deploy-an-app/app-dependencies#apt-get-dependencies

Which packages to add is distribution dependent. This web page tells you the first one: https://askubuntu.com/questions/1060903/importerror-libgthread-2-0-so-0-cannot-open-shared-object-file-no-such-file-o

With the errors that will follow, search for "pyqt" and error details and find your packages. At the end, please put the list here for future reference.

On ubuntu-18.04 (our testing machines) we also need libxkbcommon-x11-0.

TonciG commented 3 years ago

Managed to solve the problem and deploy my web app on Streamlit cloud. Attached here are requirements.txt and packages.txt that do the trick. Link to the repo is: https://github.com/TonciG/Telecom-Customer-Churn---Web-App requirements.txt packages.txt Many thanks Marko for all your help!

markotoplak commented 3 years ago

Good to know. Thanks for reporting your progress and packages.