Ask Your Question

import cv2 leads to "segmentation fault"

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

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

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

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

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

moHe gravatar image

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

I think you should check if some file like 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:


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

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

Build opencv again and this should be resolved for you:

Oneline install:

$ curl -fsSL | [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


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/".

Program received signal SIGSEGV, Segmentation fault. 0x00007ffff145d066 in google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned long) () from /home/markovv/.opencv/lib/ (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 -0600 )edit

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

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

Yup, I have it.

HotSince7cc gravatar imageHotSince7cc ( 2017-10-16 15:18:51 -0600 )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 -0600 )edit

Did the build script finish without errors?

whizzzkid gravatar imagewhizzzkid ( 2017-10-16 16:41:19 -0600 )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 -0600 )edit

@HotSince7cc Probably some Protobuf conflicts / path handling.

Maybe related: Various build fixes #1413

Eduardo gravatar imageEduardo ( 2017-10-19 04:20:38 -0600 )edit

Question Tools

1 follower


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

Seen: 5,276 times

Last updated: Oct 19 '17