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

opencv: undefined symbol: __atomic_fetch_add_8 #59

Open
bennuttall opened this issue Nov 7, 2019 · 14 comments
Assignees

Comments

@bennuttall
Copy link
Collaborator

@bennuttall bennuttall commented Nov 7, 2019

Package name: opencv-python
Issue type: Broken package
Link to PyPI page: https://pypi.org/project/opencv-python
Link to piwheels page: https://www.piwheels.org/project/opencv-python
Version: all
Python version: all
More information:

When you import cv2 you get the following error:

pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/cv2/__init__.py", line 3, in <module>
    from .cv2 import *
ImportError: /home/pi/cv2/cv2.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: __atomic_fetch_add_8

The workaround is:

pi@raspberrypi:~ $ LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1 python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> 

But this can be fixed by rebuilding all the opencv files (sorry @waveform80).

@MichK1

This comment has been minimized.

Copy link

@MichK1 MichK1 commented Nov 8, 2019

On my Raspberry Pi 3 model B importing opencv installed via package opencv-contrib-python versions 3.6.27 or earlier works fine. However, it fails with above mentioned error for package version 3.7.28, but it works with provided workaround.

@rob-smallshire

This comment has been minimized.

Copy link

@rob-smallshire rob-smallshire commented Nov 10, 2019

This issue has consumed a lot of my time, and the list of successful build on the PiWheels website got me thinking about what constitutes a successful build. Are there any smoke tests which check that it's possible to import the built package? This failing OpenCV build would fail even the most rudimentary test on a Raspberry Pi 3. I'd be happy to help get such tests in place, but it's not clear to me how these wheels are actually constructed, and where the build scripts are.

@waveform80

This comment has been minimized.

Copy link

@waveform80 waveform80 commented Nov 10, 2019

@rob-smallshire : https://github.com/waveform80/cvcluster - new-setup.py is probably the most important bit for the purposes of actually producing the wheels - all the rest is just machinery for the cluster.

@rob-smallshire

This comment has been minimized.

Copy link

@rob-smallshire rob-smallshire commented Nov 11, 2019

@waveform80 Any chance you could put a license on this repo? It strikes me as important and useful. There's use-case for building Raspberry Pi compatible wheels which include the proprietary bits which the PiWheels can't host as binaries, but which individuals could build into a wheel themselves.

@jjppython

This comment was marked as resolved.

Copy link

@jjppython jjppython commented Nov 11, 2019

Have the same issue. I am trying to install OpenCV on Raspberry Pi 4. Its a clean install and still getting the following error. I am using the python IDLE.

Traceback (most recent call last):
File "/home/pi/Desktop/Age_Classification_Try/Try2/age_try6.py", line 1, in
import cv2
File "/usr/local/lib/python3.7/dist-packages/cv2/init.py", line 3, in
from .cv2 import *
ImportError: /usr/local/lib/python3.7/dist-packages/cv2/cv2.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: __atomic_fetch_add_8

@bennuttall

This comment was marked as resolved.

Copy link
Collaborator Author

@bennuttall bennuttall commented Nov 11, 2019

Did the workaround work for you?

@barrysaik

This comment was marked as resolved.

Copy link

@barrysaik barrysaik commented Nov 11, 2019

@rasha4321

This comment has been minimized.

Copy link

@rasha4321 rasha4321 commented Nov 13, 2019

On my Raspberry Pi 3 model B importing opencv installed via package opencv-contrib-python versions 3.6.27 or earlier works fine. However, it fails with above mentioned error for package version 3.7.28, but it works with provided workaround.

hi can you help me in how to install a previous version as i am failing to do so and getting the error with latest version

@rasha4321

This comment has been minimized.

Copy link

@rasha4321 rasha4321 commented Nov 13, 2019

hi can you help me to know how to use the workaround in thony IDE or as of now it only works if i use it in terminal

@bennuttall

This comment has been minimized.

Copy link
Collaborator Author

@bennuttall bennuttall commented Nov 13, 2019

Open Thonny from the command line the same way:

pi@raspberrypi:~ $ LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1 thonny &
@JolleJolles

This comment has been minimized.

Copy link

@JolleJolles JolleJolles commented Nov 13, 2019

I am also trying to get opencv installed on the standard python3 (3.7) on my raspberry pi. The provided solution above works, but would be interested to hear about another command that only needs to be run once.

Update: I found installing a version of opencv < 4.0 works: pip install opencv-contrib-python==3.4.3.18

@jfabdo

This comment has been minimized.

Copy link

@jfabdo jfabdo commented Nov 15, 2019

I tried to set this in my python file so that I wouldn't have to run a separate script like so:

import OS

os.environ['LD_PRELOAD'] = '/usr/lib/arm-linux-gnueabihf/libatomic.so.1'

and that runs before I import cv2.

However, I still get the same error. It works if I export it from the terminal. Any ideas how to work this into a python program?

@rob-smallshire

This comment has been minimized.

Copy link

@rob-smallshire rob-smallshire commented Nov 16, 2019

@jfabdo It's not sufficient to have the variable set in Python. It needs to be seen by the Linux dynamic linker before Python is loaded. I have speculatively tried a few things like loading libatomic from within Python using ctypes, but I didn't really expect this to work, and indeed it didn't.

@eoinoc

This comment has been minimized.

Copy link

@eoinoc eoinoc commented Nov 17, 2019

I am also trying to get opencv installed on the standard python3 (3.7) on my raspberry pi. The provided solution above works, but would be interested to hear about another command that only needs to be run once.

Update: I found installing a version of opencv < 4.0 works: pip install opencv-contrib-python==3.4.3.18

Installing the previous version worked for me to import cv2:

pip install opencv-contrib-python==4.1.0.25

Perhaps there is a bug in the latest version 4.1.1.26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants
You can’t perform that action at this time.