conda can't find cv2 lib located at /opt/conda/python/3.6/cv2.cpython-36m-x86_64-linux-gnu.so

asked 2018-11-20 06:37:07 -0600

khurram gravatar image

updated 2018-11-20 06:49:13 -0600

I have compiled opencv from source and used following flag to install it in anaconda lib path -DCMAKE_INSTALL_PREFIX=/opt/conda -DCMAKE_BUILD_TYPE=Release (blah blah) after running make install the opencv lib gets installed at /opt/conda/python/3.6/cv2.cpython-36m-x86_64-linux-gnu.so which is a bit strange as I was expecting to be installed in /opt/conda/lib directory. More importantly when I try to do import cv2 inside python terminal, I get a ModuleNotFoundError error. OpenCV is also not showing in conda list. Am I missing something here? Where should OpenCV be installed to get it imported in Ananconda ?

For completeness my LD_LIBRARY_PATH and PATH are given below:

LD_LIBRARY_PATH= /opt/conda/lib:/usr/local/nvidia/lib:/usr/local/nvidia/lib64

PATH=/opt/conda/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

PS: I am able to import OpenCV in Anaconda after doing cp /opt/conda/python/3.6/cv2.cpython-36m-x86_64-linux-gnu.so /opt/conda/lib/python3.6/site-packages/cv2.so but this is not a proper solution as I have to do it after each compilation. What CMAKE_INSTALL_PREFIX should I set to get it installed at the right place.

edit retag flag offensive close merge delete

Comments

which opencv version is it ?

berak gravatar imageberak ( 2018-11-20 06:46:27 -0600 )edit
1

Branch = 4.0.0-rc

khurram gravatar imagekhurram ( 2018-11-20 06:47:20 -0600 )edit

-DCMAKE_INSTALL_PREFIX is only for the c++ libs, not for your python so.

btw, did you build it with -DBUILD_SHARED_LIBS=OFF ? (you should, so it does not depend on other opencv libs / so's later)

berak gravatar imageberak ( 2018-11-20 06:48:49 -0600 )edit

Ohh. Did it change in 4.0.0 or it was always this way? Secondly, is there any separate flag for python installation directory?

khurram gravatar imagekhurram ( 2018-11-20 06:50:19 -0600 )edit

ATM I used -DBUILD_SHARED_LIBS=ON. But I can recompile with -DBUILD_SHARED_LIBS=OFF. I am still a bit lost about python installation path. Is there any proper way to get libraries installed in right directory of Anaconda?

khurram gravatar imagekhurram ( 2018-11-20 06:57:04 -0600 )edit

Did it change in 4.0.0 or it was always this way

it was always like this

is there any separate flag for python installation directory?

hmm, it should get inferred by looking at your python install. unfortunately, conda differs a lot from what "ordinary" snakes do there.

also , there were a couple of changes in the detection / installl process recently, you'll probably have to scan the github pr backlog here

berak gravatar imageberak ( 2018-11-20 06:59:07 -0600 )edit

conda differs a lot from what "ordinary" snakes do there.

That's true. But this conda snake is getting sharper each day; (Intel MKL supported NUMPY distributions etc.) So adding conda supported flags etc will help the community.

Thanks for pointing the direction. I'll go through the PRs and will see if I can find something helpful.

khurram gravatar imagekhurram ( 2018-11-20 07:04:23 -0600 )edit