Unable to deploy Flask app with OpenCV to Cloud Foundry (linux)

I am currently developing a Python Flask app on Windows, but deploying to Cloud Foundry on linux. I was able to successfully deploy the app before I integrated opencv for additional features. Application is also successfully running on local.

I am using Python 3.6.7 and the first error I’ve encountered was ImportError: libGL.so.1: cannot open shared object file: No such file or directory.

After trying upgrading and downgrading to various Python versions, the current error is that there is an extremely long time when deploying the application which will result in a timeout error as seen below.

...
Running setup.py install for future: started
              Running setup.py install for future: finished with status 'done'
            Running setup.py install for pyxnat: started
              Running setup.py install for pyxnat: finished with status 'done'
            The script flask is installed in '/tmp/contents787828360/deps/0/python/bin' which is not on PATH.
            Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
            The scripts imageio_download_bin and imageio_remove_bin are installed in '/tmp/contents787828360/deps/0/python/bin' which is not on PATH.
            Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
            The script jsonpath_ng is installed in '/tmp/contents787828360/deps/0/python/bin' which is not on PATH.
            Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
            Running setup.py install for opencv-python: started
              Running setup.py install for opencv-python: still running...
              Running setup.py install for opencv-python: still running...
              Running setup.py install for opencv-python: still running...
              Running setup.py install for opencv-python: still running...
              Running setup.py install for opencv-python: still running...
              Running setup.py install for opencv-python: still running...
              Running setup.py install for opencv-python: still running...
              Running setup.py install for opencv-python: still running...

I have tried changing from opencv-python to opencv-python-headless (unable to run on windows local) and opencv-contrib-python (same issue when deploying). Also tried adding an Aptfile and tuning various OpenCV versions but to no avail.

Currently my issue is that the build has failed during deployment. Any insights will really help thank you.

that seems to be the way to go. what exactly went wrong, locally ?
how exactly are you trying to install it ? (it probably should not build anything)
(and which opencv version is it ?)

I am currently using 4.3.0.38 which was chosen randomly. Initially I installed opencv without specifying the version and it was 4.5.2.52 but during deployment I got this warning, which resulted me in downgrading it.

Could not find a version that satisfies the requirement opencv-python==4.5.2.54 (from -r /tmp/app/requirements.txt (line 32)) (from versions: 3.1.0.4, 3.1.0.5, 3.2.0.6, 3.2.0.7, 3.2.0.8, 3.3.0.9, 3.3.0.10, 3.3.1.11, 3.4.0.12, 3.4.0.14, 3.4.1.15, 3.4.2.16, 3.4.2.17, 3.4.3.18, 3.4.4.19, 3.4.5.20, 3.4.6.27, 3.4.7.28, 3.4.8.29, 3.4.9.31, 3.4.9.33, 3.4.10.37, 3.4.11.39, 3.4.11.41, 3.4.11.43, 3.4.11.45, 3.4.13.47, 4.0.0.21, 4.0.1.23, 4.0.1.24, 4.1.0.25, 4.1.1.26, 4.1.2.30, 4.2.0.32, 4.2.0.34, 4.3.0.38, 4.4.0.40, 4.4.0.42, 4.4.0.44, 4.4.0.46, 4.5.1.48)

Actually I just checked again, the opencv-python-headless is now working fine but faces the same issue of the timeout error during the app deployment. Build may not be a correct word sorry! I just pip install the package.

I’ve read elsewhere that this can possibly be resolved with pip upgrade but it’s not easily achievable in Cloud Foundry (unlike local com).

Any idea why the deployment is having a time out error running the setup.py?

hmm, if there’s no adequate prebuilt package for that platform / opencv version, it might indeed try to build it from src, which may take up to 2 hours

Is there any way I can work around this? Perhaps installing the package via a url or different format within my requirements.txt?

With reference to my previous reply, they returned a message saying that my opencv does not satisfy the versions that they accept. Does that mean that the platform accepts the specific versions because it’s included in a prebuilt package?

The timeout happens after 15mins and hours for deployment is too long unfortunately… :cold_face: