Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import error cv2.so: undefined symbol: _ZN2cv8Stitcher17estimateTransformERKNS_11_InputArrayE #13226

Closed
abhiTronix opened this issue Nov 20, 2018 · 8 comments

Comments

@abhiTronix
Copy link

abhiTronix commented Nov 20, 2018

System information (version)
  • OpenCV => Latest 4.0.0 (Master Branch)
  • Operating System / Platform => Ubuntu 18.04.1 LTS
  • Compiler => GCC 7.3.0
Detailed description

All Python Bindings Seems Broken:(See below)

Python 2.7.15rc1:

abhishek@abhishek-HP-Pavilion-Notebook:~/Downloads/opencv-master/build_tbb$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/python2.7/dist-packages/cv2.so: undefined symbol: _ZN2cv8Stitcher17estimateTransformERKNS_11_InputArrayE
>>> 

Python 3.6.6:

abhishek@abhishek-HP-Pavilion-Notebook:~/Downloads/opencv-master/build_tbb$ python3
Python 3.6.6 (default, Sep 12 2018, 18:26:19) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/python3.6/dist-packages/cv2.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN2cv8Stitcher17estimateTransformERKNS_11_InputArrayE
>>> 
Debug Files:

Strace:
python2.txt
python3.txt

@abhiTronix abhiTronix changed the title Import error cv2.so: undefined symbol: _ZN2cv8Stitcher17estimateTransformERKNS_11_InputArrayE >>> Import error cv2.so: undefined symbol: _ZN2cv8Stitcher17estimateTransformERKNS_11_InputArrayE Nov 20, 2018
@alalek
Copy link
Member

alalek commented Nov 20, 2018

How did you get these bindings?

@abhiTronix
Copy link
Author

abhiTronix commented Nov 21, 2018

How did you get these bindings?

@alalek Compiled from source(Master-branch):

cmake -DCMAKE_CXX_FLAGS=" -march=bdver1 -ftree-vectorize" -DEXTRA_C_FLAGS="-march=bdver1 -ftree-vectorize" -DEXTRA_CXX_FLAGS="-march=bdver1 -ftree-vectorize" -DOPENCV_EXTRA_SHARED_LINKER_FLAGS="-Wl,-Bsymbolic" -DBUILD_TESTS=OFF  -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_TESTS=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DBUILD_EXAMPLES=OFF -DOPENCV_EXTRA_MODULES_PATH=/home/abhishek/Downloads/opencv_contrib-master/modules -DWITH_LIBV4L=0N  -DWITH_V4L=ON -DWITH_JPEG=ON -DOPENCV_ENABLE_NONFREE=ON ..

Which yield following output:
cmake_output.txt

thereby compiled and installed on my system(without any errors):

make -j4
sudo make install
sudo ldconfig

Even tried to build it in new folder, but same results(all python bindings doesn't seems to work) :(

@abhiTronix
Copy link
Author

abhiTronix commented Nov 22, 2018

@alalek Solved it myself.

Wrong installation path for cv2.so(Screenshot Below) lib for python in OpenCV [must be/usr/local/lib/python2.7/dist-packages/cv2.so instead], Kindly correct this bug. Thankyou

screenshot from 2018-11-22 11-07-41

@alalek
Copy link
Member

alalek commented Nov 22, 2018

Be careful with multiple calls of "make install" - they didn't uninstall previous versions so your system become inconsistent.
For development it is enough to use build directory. Please leave "make install" for package maintainers.

Python path changes are here: #13202

@abhiTronix
Copy link
Author

abhiTronix commented Nov 22, 2018

@alalek

Be careful with multiple calls of "make install" - they didn't uninstall previous versions so your system become inconsistent.

Yes, that was the problem indeed. I uninstalled any previous file related to OpenCV and built the latest commit successfully today. The new features like Vulkan backend DNN are awesome!!!!

Python path changes are here: #13202

Yes, I made Python path changes as suggested in #13202 and used the default(old) configuration by commands as below:

OPENCV_SKIP_PYTHON_LOADER=ON
OPENCV_PYTHON_INSTALL_PATH=...site/dist-packages location...
OPENCV_PYTHON3_INSTALL_PATH=...site/dist-packages location...

But still the Python 2.7 binding lib[cv2.so] was installed at the wrong destination(as seen in my screenshot), whereas Python 3.6 bindings where installed at the correct place(i.e. /usr/local/lib/python2.7/dist-packages/cv2.cpython-36m-x86_64-linux-gnu.so). There is still a bug or something wrong with python 2.7 path. I moved the file[cv2.so] manually as a workaround and everything is ok for now

@alalek
Copy link
Member

alalek commented Nov 22, 2018

There are two paths (PYTHON -> PYTHON3 | PYTHON2 ):

  • OPENCV_PYTHON3_INSTALL_PATH
  • OPENCV_PYTHON2_INSTALL_PATH

@abhiTronix
Copy link
Author

There are two paths (PYTHON -> PYTHON3 | PYTHON2 ):

OPENCV_PYTHON3_INSTALL_PATH
OPENCV_PYTHON2_INSTALL_PATH

@alalek Ohh I was doing it wrong, I thought it was OPENCV_PYTHON_INSTALL_PATH. I'll correct it now. Thanks once again 👍

@harinduravin
Copy link

harinduravin commented Oct 29, 2021

Python 3.7.9 (default, Aug 31 2020, 12:42:55)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
--> import cv2
Traceback (most recent call last):
File "", line 1, in
File "/home/ace/anaconda3/envs/tf1/lib/python3.7/site-packages/cv2/init.py", line 129, in
bootstrap()
File "/home/ace/anaconda3/envs/tf1/lib/python3.7/site-packages/cv2/init.py", line 112, in bootstrap
import cv2
ImportError: /home/ace/anaconda3/envs/tf1/lib/libopencv_text.so.4.5: undefined symbol: _ZGVbN2v___log_finite

Getting a similar type of error. Unable to figure out.

Update:

gcc -shared -Wall $FILES -lm -o libopencv_text.so.4.5

Several similar files resulted in the same error. After correcting several files this way.

Python 3.7.9 (default, Aug 31 2020, 12:42:55)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
--> import cv2
Traceback (most recent call last):
File "", line 1, in
File "/home/ace/anaconda3/envs/tf1/lib/python3.7/site-packages/cv2/init.py", line 129, in
bootstrap()
File "/home/ace/anaconda3/envs/tf1/lib/python3.7/site-packages/cv2/init.py", line 112, in bootstrap
import cv2
ImportError: dynamic module does not define module export function (PyInit_cv2)

Update:

It seems the problem was some library in my Conda environment was conflicting. I'm not sure about that, because I initially tried to build opencv 4.5.3 from source. Then I tried to remove the build and install an older version 4.3.0 instead. Then also few similar errors appeared. After uninstalling few libraries from Conda environment and then reinstalling some helped me overcome this import cv2 error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants