Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python OpenCV import error with python 3.5

Tags:

python

opencv

I am having some difficulties installing opencv with python 3.5.

I have linked the cv files, but upon import cv2 I get an error saying ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/cv2.so, 2): Symbol not found: _PyCObject_Type or more specifically:

/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/Jamie/Desktop/tester/test.py Traceback (most recent call last): File "/Users/Jamie/Desktop/tester/test.py", line 2, in import cv File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/cv.py", line 1, in from cv2.cv import * ImportError:dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/cv2.so, 2): Symbol not found: _PyCObject_Type Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/cv2.so Expected in: flat namespace in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/cv2.so

I have linked cv.py and cv2.so from location /usr/local/Cellar/opencv/2.4.12_2/lib/python2.7/site-packages correctly into /Library/Frameworks/Python.framework/Versions/3.5/bin

Would anybody be able to help please?

Thanks very much

like image 339
JamieS Avatar asked Feb 07 '23 21:02

JamieS


2 Answers

No need to change the python version, you can just use the pip command open cmd ( admin mode) and type

pip install opencv-python

like image 190
aman Avatar answered Feb 20 '23 14:02

aman


Found an answer - follow the instructions on this website BUT you have to change to the version of python you are using.

Also, I didn't bother with the virtual environments.

And lastly cv2.so is actually called cv2.cpython-35m-darwin.so in the build/lib folder that you make.

Then it works.

like image 41
JamieS Avatar answered Feb 20 '23 14:02

JamieS