Ask Your Question
0

import cv2 leads to "segmentation fault"

asked 2017-09-07 07:35:27 -0500

herleeyandi gravatar image

Hello I am installing opencv and opencv-contrib in my ubuntu pc. I installed it in both python 2 and 3. I have successfully installed it. However when I doing "import cv2" it immediately produce "segmentation fault (core dumped)". It happens in both python 2 and python 3. So how can I fix this problem? Here is my full problem see problem

-Thank you-

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
0

answered 2019-10-29 05:59:16 -0500

tik0 gravatar image

I had the same issue and solved it as follows:

Check if your linker finds any 3rd party libraries which you have installed on your system (in my case it was "/usr/NX/lib" which came with its own gtk libraries): LD_DEBUG=files python -c "import cv2"

  1. If you have installed opencv through a package manager, check your LD_LIBRARY_PATH variable and remove the entries if existent
  2. If you have built opencv from source, you have to exclude the folder from the cmake search path (e.g. -D CMAKE_IGNORE_PATH=/usr/NX/lib)
edit flag offensive delete link more
0

answered 2017-10-17 09:58:31 -0500

moHe gravatar image

updated 2017-10-19 08:19:05 -0500

I think you should check if some file like cv.so has been already in your py2's and py3's lib/sitepackages/ (or anywhere in your python's path--

import sys

for i in sys.path:

    print(i)

Only if it's done, the cv2 lib can be found by you python, and then the cv2 can be imported.

edit flag offensive delete link more
-2

answered 2017-09-18 11:40:48 -0500

Build opencv again and this should be resolved for you: https://github.com/whizzzkid/opencv-c...

Oneline install:

$ curl -fsSL http://bit.ly/OpenCV-Latest | [optirun] bash -s /path/to/download/folder

If it does not work try:

$ gdb python
(gdb) run -c "import cv2"

Post the error here.

edit flag offensive delete link more

Comments

Hi, I get the following output:


(gdb) run -c "import cv2"

Starting program: /usr/bin/python3 -c "import cv2" [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault. 0x00007ffff145d066 in google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned long) () from /home/markovv/.opencv/lib/libopencv_dnn.so.3.3 (gdb)

Any idea how to solve it? Maybe I have some problem with my system( I'm running Linux Mint 18.2 KDE)

HotSince7cc gravatar imageHotSince7cc ( 2017-10-16 06:01:06 -0500 )edit

Did you have also OpenCV contrib when you had the error?

Eduardo gravatar imageEduardo ( 2017-10-16 10:01:45 -0500 )edit

Yup, I have it.

HotSince7cc gravatar imageHotSince7cc ( 2017-10-16 15:18:51 -0500 )edit

Can you try without the contrib module? Make sure to remove everything in the build directory and start from scratch.

Eduardo gravatar imageEduardo ( 2017-10-16 16:25:05 -0500 )edit

Did the build script finish without errors?

https://raw.githubusercontent.com/whi...

whizzzkid gravatar imagewhizzzkid ( 2017-10-16 16:41:19 -0500 )edit

It worked. Thanks. I built it without the contrib module. What is wrong with it, just curious? Any idea?

HotSince7cc gravatar imageHotSince7cc ( 2017-10-17 05:45:38 -0500 )edit

@HotSince7cc Probably some Protobuf conflicts / path handling.

Maybe related: Various build fixes #1413

Eduardo gravatar imageEduardo ( 2017-10-19 04:20:38 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-09-07 07:35:27 -0500

Seen: 3,300 times

Last updated: Oct 19 '17