0

I'm trying to deploy my web app on pythonanywhere and I need OpenCv with cotrib modules on it. So I compiled it using the following cmake config:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON \
-D BUILD_opencv_python3=yes ..

since I can't be root on pythonanywhere bash, I then installed OpenCv using DESTDIR:

make install DESTDIR=/home/pathToInstallationDir...

No problems with installation, but python console could not yet import cv2. Thanks to point 7 of this answere: Why cv2.so missing after opencv installed? I exported python path and it now tryes to import cv2 with following error log:

     File "<stdin>", line 1, in <module>
        File "/home/pathToInstallationDir.../usr/local/lib/python3.6/site-packages/cv2/__init__.py", line 96, in <module>
        bootstrap()
        File "/home/spir/pathToInstallationDir.../usr/local/lib/python3.6/site-packages/cv2/__init__.py", line 86, in bootstrap
        import cv2
    ImportError: libopencv_hdf.so.4.4: cannot open shared object file: No such file or directory

So I guess there is a enviroment variable specified in __init__.py module that python interpreter follows to find all .so in lib and it is the wrong one at the moment, cause i looked for libopencv_hdf.so.4.4 and is located in lib as it should be.

Am I correct? if yes, which variable is the incriminated one and how do i change it?

if not, what could be the right diagnosis for the problem?

please help.

Aleningi
  • 3
  • 3
  • 1
    "since I can't be root on pythonanywhere bash, I then installed OpenCv using `DESTDIR`" - No, this is **wrong** approach for change *installation directory*. The correct one is setting `CMAKE_INSTALL_PREFIX` parameter when call `cmake`. If you don't have rights to write under `/usr/local`, then change this parameter to something else. Installed files could refer to other installed files using **absolute paths**. These paths are determined on **configuration** stage, so they could take into account `CMAKE_INSTALL_PREFIX` variable. But `DESTDIR` is not known at configuration stage. – Tsyvarev Jun 26 '20 at 12:04
  • The error `cannot open shared object file` could be resolved by setting `LD_LIBRARY_PATH` environment variable. Have you tried that? Have you checked that question: https://stackoverflow.com/questions/1099981/why-cant-python-find-shared-objects-that-are-in-directories-in-sys-path? – Tsyvarev Jun 26 '20 at 12:08
  • @Tsyvarev Thank you, i set the variable LD_LIBRARY_PATH and it worked! it was exactly what i needed! You can put it as an answer and i will set it as the right one – Aleningi Jul 03 '20 at 18:04

0 Answers0