4
votes

When invoked in python, cv2 is looking for the wrong libcudart.so. Here is the error after import cv2

ImportError: libcudart.so.6.5: cannot open shared object file: No such file or directory.

I have both CUDA 6.5 and 7.5 installed on my system. But other apps seem to have no problem finding 7.5.

Here is my settings : ubuntu 14.04, OpenCV 3.0.0, python 2.7, cuda 6.5 and cuda 7.5

The LD_LIBRARY_PATH looks like

/usr/local/cuda/lib64:/usr/local/lib:/home/rspace/shogun-4.0.0/build-release/src/shogun:/usr/lib:/usr/lib/x86_64-linux-gnu

NOTE: the /usr/local/cuda is actually a link to /usr/local/cuda-7.5.

2
What is the full path to libcudart.so.6.5 on your system? It's likely that /usr/local/cuda is actually a symlink on your system that actually points to /usr/local/cuda-7.5, so the /usr/local/cuda/lib64 entry in your LD_LIBRARY_PATH won't allow codes that are built against CUDA 6.5 to find the appropriate libraries. You could try adding the exact path to libcudart.so.6.5 to your LD_LIBRARY_PATH. Regarding the "wrong" libcudart.so, the application will "look for" whichever one it was built against (linked against). An app linked against CUDA 6.5 can't use the CUDA 7.5 libraries instead - Robert Crovella
full path : /usr/local/cuda-6.5/lib64. And yes, /usr/local/cuda indeed points to cuda-7.5. - horaceT
The OpenCV was just built rebuilt from source with cmake : cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON .. - horaceT
Notice it does not have the flag CUDA_GENERATION=Auto. I'm wondering if that might be needed. - horaceT
@horaceT: please add a short answer summarising the solution you found to the problem - talonmies

2 Answers

3
votes

To make the long story short, here is what happened.

I have two OpenCVs in my system. One was compiled and built on CUDA 6.5, but it was never make installed. Before last week, I had PYTHONPATH set to the .../release/lib of this local folder, which is somewhere in my user home directory. At the same time, my LD_LIBRARY_PATH has a subpath /usr/local/cuda/lib64, where /usr/local/cuda is actually a symlink pointing to CUDA 6.5.

Previously when I invoked import cv2, python knew where to look thanks to PYTHONPATH and opencv knew where to find CUDA thanks to LD_LIBRARY_PATH.

Last week I bought a new nvidia GPU; when installing it I upgraded CUDA to 7.5. In doing so, the symlink /usr/local/cuda was changed to point to cuda-7.5.

Thus, when invoking in python, cv2 was still going to the same symlink, but saw all the stuff associated with 7.5, and it was confused.

To make cv2 work again, all i have to do is to add the cuda 6.5 to LD_LIBRARY_PATH, as suggested by Mr. Crovella. However, that doesn't solve my problem because I want to use the new opencv compiled on CUDA 7.5, but that belongs to a different thread...

1
votes

I had the same problem. I solved that problem by installing `opencv-python:

$pip install opencv-python

this instruction works for me