How to remove a Python package from Streamlit Cloud

Hello everyone. I am facing a very stupid and annoying issue. I am trying to deploy an application to the Streamlit Cloud. Among required Python packages I have the OpenCV. It’s well known that Streamlit Cloud works only with the headless version of OpenCV. So my requirements.txt file just looks like this:

streamlit
opencv-python-headless

After deploying the app to my Streamlit Cloud with such requirements everything works just fine and in logs I can see the next version of OpenCV installed:

opencv-python-headless-4.6.0.66

However as the next step for my application I also need to install another Python package MediaPipe. So to make everything work I just add another line to my requirements.txt and it looks like this:

streamlit
opencv-python-headless
mediapipe

And it results to my app crash with the error:

Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/scriptrunner/script_runner.py", line 557, in _run_script
    exec(code, module.__dict__)
  File "streamlit_app.py", line 2, in <module>
    import cv2
  File "/home/appuser/venv/lib/python3.9/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/appuser/venv/lib/python3.9/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

Or in a nutshell:

ImportError: No module named cv2

And among the other modules in my app I can see in logs the next two lines:

opencv-contrib-python-4.6.0.66 
opencv-python-headless-4.6.0.66

So it looks like the MediaPipe module has it’s own dependencies with the OpenCV module and it implicitly installs it to the system. As long as this is the contrib (not headless) version of the OpenCV, it results into a crash of my app at the Streamlit Cloud.

Any ideas how to fix it? Maybe there is something like a terminal for my Streamlit Cloud app where I can just remove an unwanted Python package with pip uninstall command? Or I can somehow control these processes throughout the requirements.txt file? The search in the Internet and the Forum haven’t given me options like these.

I will be glad to have any help here guys. Thanks!

Hi @zharsky :wave:

Take a look at: ImportError libGL.so.1 cannot open shared object file No such file or directory - Streamlit Docs

If opencv-python is a required (non-optional) dependency of your app or a dependency of a library used in your app, then:

  • Include opencv-python in requirements.txt and
  • Include libgl1 in packages.txt.
2 Likes

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