[Streamlit sharing] Importerror: libgl.so.1: cannot open shared object file: no such file or directory opencv error [

Hi I am having a error message while I was trying to deploy the app through Streamlit Sharing.

[Importerror: libgl.so.1: cannot open shared object file: no such file or directory opencv error]

I have added both requirements.txt, and packages.txt in https://share.streamlit.io/djshan1979/webtools-fitbit4food/main/ but still have the same message.

How can I resolve this?

The last part of traceback is like below

Traceback (most recent call last):
File “/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py”, line 333, in _run_script exec(code, module.dict)
File “/app/webtools-fitbit4food/streamlit_recommedation_engine_with_session_18_04_2021.py”, line 15, in import cv2
File “/home/appuser/venv/lib/python3.7/site-packages/cv2/init.py”, line 5, in
from .cv2 import *

ImportError: libGL.so.1: cannot open shared object file: No such file or directory
[client] Connecting…

The requirements.txt is

streamlit==0.79.0
opencv-python-headless==4.5.1.48
textblob==0.15.3
scipy==1.6.1
numpy==1.19.2
pytesseract==0.3.7
nltk==3.5
pandas==1.2.2
scikit-learn==0.24.2

the packages.txt is like

freeglut3-dev
libgtk2.0-dev

Hi @djshan1979

I think you can just keep opencv-python-headless and remove opencv_python from the requirements.txt file. This might cause an opencv conflict and the above issue.

Please refer to the similar link - Importerror: libgl.so.1: cannot open shared object file: no such file or directory opencv error

Thanks @Pratip_Khandelwal I’ve tried it but it didn’t make any difference in result.

Hey @djshan1979 it would be good if you can share the code repo to debug.

Hi Pratip
Thanks for your comment.

Here is my Code Repot

Streamlit Sharing
https://share.streamlit.io/djshan1979/webtools-fitbit4food/main/streamlit_recommedation_engine_with_session_18_04_2021.py

Github

Thanks

The requirements.txt file contains several incorrectly named packages.

  • remove line with: opencv_python
  • package name should be: opencv-python-headless
  • package name should be: scikit-learn

Thanks for your message, @Franky1
I double checked my requirements.txt file and only found difference for scikit_learn so I changed it as scikit-learn, however it still has the same message unfortunately.
When I googled this issue, many posts say that they’ve resolved this issue with ‘sudo apt install libgl1-mesa-glx’, Do you have an idea how to add this library in my package as I couldn’t find this in both Python prompt and Pycharm.
Or whatelse can I do more in order to fix this out.?

Hi @djshan1979 :grinning_face_with_smiling_eyes:

If you’re looking to run sudo apt install libgl1-mesa-glx, I would suggest adding libgl1-mesa-glx to your packages.txt. With the addition, your packages.txt should look like so:

freeglut3-dev
libgtk2.0-dev
libgl1-mesa-glx

Do let us know if this :point_up:works or you’re still receiving the same error.

Happy Streamlit-ing! :balloon:
Snehan

Hi @snehankekre Thanks for your reply, I’ve added libgl1-mesa-glx to my packages.txt and more.

freeglut3-dev
libgtk2.0-dev
libgl1-mesa-glx
ffmpeg
libsm6
libxext6
libxrender1
libfontconfig1

Unfortunately, still has the same error

1 Like

Hi @djshan1979, thanks for getting back to me :slightly_smiling_face:

I was able to fork your repo and successfully deploy the app on Streamlit Sharing after adding a packages.txt file! Here are the contents of both the files:

packages.txt

freeglut3-dev
libgtk2.0-dev
libgl1-mesa-glx
tesseract-ocr
libtesseract-dev
libtesseract4
tesseract-ocr-all

requirements.txt

streamlit
opencv-python-headless
textblob
scipy
numpy
pytesseract
nltk
pandas
scikit-learn

Your repo seems to be missing packages.txt. Adding the above :point_up: packages.txt file, in addition to replacing opencv-python with opencv-python-headless in requirements.txt worked on my end.

Lastly, for pytesseract to work, you need to install the tesseract binary via packages.txt and replace line 19 of your scorecard_generation.py with:

pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'

Let me know if you’re still running into the same error after making these changes :mag:

Happy Streamlit-ing! :balloon:
Snehan

3 Likes

Hi @snehankekre, Thank you for solving the OpenCV problem. I would like to know how can I use private Github repository with streamlit. or can I use streamlit for my private project?

  • Can I associate my domain with streamlit?

Hi @HimanshuMoliya :grinning:

You will not be able to deploy a private GitHub repository on Streamlit Sharing.

This feature will be offered via Streamlit for Teams when we release it later this year. Streamlit for Teams is currently in a private Beta. You can learn more and sign up for updates at this link:

Would you mind clarifying what you mean by

Can I associate my domain with streamlit?

Best, :balloon:
Snehan

Can I use my custom domain E.g. “xyz.com” instead of https://share.streamlit.io/ for my application?

Hi @HimanshuMoliya, hosting apps deployed via Streamlit Sharing on your custom domains is currently not possible.

The only option for now would be to forward from the xyz.com domain to the full path of the sharing app (in Namecheap that’s called a “URL Redirect Record”, not sure if it’s the same with other providers).

Best, :balloon:
Snehan

1 Like

Good morning @snehankekre
It’s so happy to get your answer and now I am able to deploy the app successfully.
Thank you so much for your support

Let me ask you the last question, how did you get what libraries should be added on packages.txt?
Is there a cheat function like pipreqs to get it?

Good question, @djshan1979! I’m not sure if there’s a pipreqs equivalent for system packages. I’ll find out.

For this specific app, I had to look up the installation process for pytesseract, and Google the errors. The stackoverflow post for the error suggested system packages to be sudo apt install 'ed. Those go in packages.txt.

1 Like

Hey @HimanshuMoliya :bulb: I just this came across this hacky workaround on Twitter regarding Streamlit Sharing and custom domains https://twitter.com/JavierFnts/status/1363522570956517380

We can’t make any guarantees as to how long or well this will work as it relies on a 3rd party. But if you try this or any other method and it works for you, do let us know! :grinning_face_with_smiling_eyes:

Happy Streamlit-ing! :balloon:
Snehan

1 Like

Hi, @snehankekre Thank you for sharing the Netlifty platform. We will try it for our application. But first I want to know how to make code private and use it via streamlit. So, feel free to notify me, when this feature is available.

I look in the documentation of the python libraries, usually there is described which external libraries are needed.

I cloned your repository and cleaned it up a bit. I tested it locally in a docker container and also on streamlit sharing. Find the repo here:

The only required packages in packages.txt seems to be:

tesseract-ocr
2 Likes

Now I understand it clearly, Really appreciate for your support, @Franky1. This helps a lot to make it simple. Cool

2 Likes