swiss_knight
swiss_knight

Reputation: 7941

Python3 Relink issue while importing opencv

Question:

I have a segmentation fault after trying to import a freshly compiled version of the latest available OpenCV from github on Ubuntu 18.04.

Here is the error message I got while trying to import cv2 in Python 3:

$ python3
Python 3.6.8 (default, Aug 20 2019, 17:12:48) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
python3: Relink `/lib/x86_64-linux-gnu/libsystemd.so.0' with `/lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol `clock_gettime'
python3: Relink `/lib/x86_64-linux-gnu/libudev.so.1' with `/lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol `clock_gettime'
Segmentation fault (core dumped)

My Ubuntu; 5.0.0-29-generic x86_64 GNU/Linux

From where I cloned OpenCV; https://github.com/opencv/opencv

Related threads;
getting error while importing cv2 module in ubuntu amazon instance
Configure AWS Redshift on Ubuntu 18.04 and use it with pyodbc
https://unix.stackexchange.com/questions/444697/cannot-run-python-file-asks-to-relink-libraries
https://github.com/tensorflow/tensorflow/issues/19375

None of the solutions presented worked as I do not have any NVidia graphic chips on my laptop;

$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation HD Graphics 5500 (rev 09)

Notice:
I need to compile OpenCV from sources because I want to use SIFT and SURF detectors and descriptors and they are no more available when OpenCV is installed with apt:

>>> import cv2
>>> cv2.__version__
'4.2.0'

>>> cv2.xfeatures2d.SIFT_create()    

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.2.0)     
/io/opencv_contrib/modules/xfeatures2d/src/sift.cpp:1210:    
error: (-213:The function/feature is not implemented)     
This algorithm is patented and is excluded in this configuration;    
Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in    
function 'create'

Upvotes: 15

Views: 13008

Answers (4)

mibison
mibison

Reputation: 31

In my case

python3.6: Relink `/lib/x86_64-linux-gnu/libsystemd.so.0' with `/lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol `clock_gettime'
python3.6: Relink `/lib/x86_64-linux-gnu/libudev.so.1' with `/lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol `clock_gettime'

was generated by

$ python3.6
import tvm

and resolved by installation of a missing library. I found out this was missing by using a different version of python, as has been suggested elsewhere. In particular I found

$ python3.7
import tvm

reports (accurately) on a missing library. Once the missing library was installed for python3.6

$ python3.6 -m pip install <missing_library>

the problem went away.

So the problem is not specific to OpenCV or CuDNN. It seems to be a problem in the error reporting in python3.6.

Upvotes: 3

Doğuş
Doğuş

Reputation: 1957

I got the same issue. In my situation, the problem was related to the CuDNN.

Cuda: 10.2
CuDNN: tried both versions 7.6.5 and 8.0.1

When I compiled OpenCV 4.4.0 from github without the CuDNN enabled, the error was gone. In another words, don't include these cmake flags when you compile the OpenCV:

-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=ON \

If you need the CuDNN support, the problem might be the CuDNN is not linked properly after installation. Make sure you run the command below after you install the CuDNN

sudo ldconfig

Run that again after the OpenCV compilation ends.

Upvotes: 0

Addison Klinke
Addison Klinke

Reputation: 1186

In my case, the error was solved by installing the OpenCV headers sudo apt install libopencv-dev. Typically I do this apt install before trying to pip install the OpenCV Python bindings

Upvotes: 4

Asmita Khaneja
Asmita Khaneja

Reputation: 355

This seems to be caused by version dependency issues. I faced the same problem, Run the below command apt install python3-opencv

This will solve the problem.

Upvotes: 11

Related Questions