15

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'
swiss_knight
  • 5,787
  • 8
  • 50
  • 92

4 Answers4

11

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.

Asmita Khaneja
  • 355
  • 1
  • 8
  • 1
    I must compile opencv from sources to be able to run tests using SIFT and SURF keypoints & descriptors (+many others), which are no more available when opencv is installed with apt: see https://stackoverflow.com/questions/37039224/attributeerror-module-object-has-no-attribute-xfeatures2d-python-opencv-2 and https://stackoverflow.com/questions/52305578/sift-cv2-xfeatures2d-sift-create-not-working-even-though-have-contrib-instal – swiss_knight Oct 22 '19 at 06:00
  • It didn't solve my problem, and neither did the links posted by s.k. As for my issue, it's related to `user:~/$ jupyter qtconsole /home/linuxbrew/.linuxbrew/opt/python@3.8/bin/python3.8: Relink `/usr/lib/x86_64-linux-gnu/libQtCore.so.4' with `/lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol `clock_gettime' Segmentation fault (core dumped)` – Andreas L. Aug 10 '20 at 11:13
4

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

Addison Klinke
  • 1,024
  • 2
  • 14
  • 23
  • 1
    It didn't solve the issue as I am building opencv from sources. – swiss_knight Jan 30 '20 at 15:27
  • It didn't solve my problem either. As for my issue, it's related to `user:~/$ jupyter qtconsole /home/linuxbrew/.linuxbrew/opt/python@3.8/bin/python3.8: Relink `/usr/lib/x86_64-linux-gnu/libQtCore.so.4' with `/lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol `clock_gettime' Segmentation fault (core dumped)` – Andreas L. Aug 10 '20 at 11:13
3

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.

mibison
  • 31
  • 3
0

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.

Doğuş
  • 1,887
  • 1
  • 16
  • 24