Issue with Flask app using OpenCV
waleed2660
HOBBYOP

2 years ago

I'm trying to deploy a flask application that uses opencv but its failing to deploy. This is the error it throws during deployment: ImportError: libGL.so.1: cannot open shared object file: No such file or directory

I want to ask if there's any way I can use the Nixipack to build the app while also run few commands inside the docker container to install few missing dependencies i.e. apt-get update && apt-get install libgl1

I've tried using headless opencv but it still threw same error.

Any help will be extremely appreciated!!

5 Replies

waleed2660
HOBBYOP

2 years ago

Here's the full stacktrace:

[2024-04-14 07:07:05 +0000] [7] [INFO] Starting gunicorn 20.0.4

[2024-04-14 07:07:05 +0000] [7] [INFO] Listening at: http://0.0.0.0:5820 (7)

[2024-04-14 07:07:05 +0000] [7] [INFO] Using worker: sync

[2024-04-14 07:07:05 +0000] [10] [INFO] Booting worker with pid: 10

[2024-04-14 07:07:05 +0000] [10] [ERROR] Exception in worker process

Traceback (most recent call last):

File "/opt/venv/lib/python3.11/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker

worker.init_process()

File "/opt/venv/lib/python3.11/site-packages/gunicorn/workers/base.py", line 119, in init_process

self.load_wsgi()

File "/opt/venv/lib/python3.11/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi

self.wsgi = self.app.wsgi()

^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi

self.callable = self.load()

^^^^^^^^^^^

File "/opt/venv/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 49, in load

return self.load_wsgiapp()

^^^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp

return util.import_app(self.app_uri)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.11/site-packages/gunicorn/util.py", line 358, in import_app

mod = importlib.import_module(module)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.nix-profile/lib/python3.11/importlib/init.py", line 126, in import_module

return _bootstrap._gcd_import(name[level:], package, level)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "", line 1204, in _gcd_import

File "", line 1176, in _find_and_load

File "", line 1147, in _find_and_load_unlocked

File "", line 690, in _load_unlocked

File "", line 940, in exec_module

File "", line 241, in _call_with_frames_removed

File "/app/handy_web.py", line 1, in

import cv2

File "/opt/venv/lib/python3.11/site-packages/cv2/init.py", line 181, in

bootstrap()

File "/opt/venv/lib/python3.11/site-packages/cv2/init.py", line 153, in bootstrap

native_module = importlib.import_module("cv2")

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/root/.nix-profile/lib/python3.11/importlib/init.py", line 126, 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

[2024-04-14 07:07:05 +0000] [10] [INFO] Worker exiting (pid: 10)

[2024-04-14 07:07:05 +0000] [7] [INFO] Shutting down: Master

[2024-04-14 07:07:05 +0000] [7] [INFO] Reason: Worker failed to boot.


honzasterba
PRO

2 years ago

you can use nixpacts config to install additional apt/nix packages

eisest done via ENV vars

https://nixpacks.com/docs/configuration/environment

or you can write a toml config file


waleed2660
HOBBYOP

2 years ago

I've tired setting up variable to make nixpacks download the apt packages and it did download them but I'm still getting the same error.


2 years ago

You would need to use a Dockerfile for projects that use opencv.


honzasterba
PRO

2 years ago

are you sure you are adding the correct pacakges? usually you need to add -dev version of packages that include headers and other libs that can be than linked when you are building your python lib


Welcome!

Sign in to your Railway account to join the conversation.

Loading...