trouble installing opencv on a mac (after opencv worked fine a few months ago)
(I posted the same question on stackoverflow: https://stackoverflow.com/questions/5...)
I have opencv installed on my mac which was working a few months ago but doesn't work anymore.
I have the following specificities. - OpenCV: 3.4.3.1 - Operating System / Platform: macOS 10.14 - Python 3.6.5
I tried to reload a python script where I used opencv. However, I got the following error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/anaconda3/lib/python3.6/site-packages/cv2.so, 2): Library not loaded: /usr/local/opt/ilmbase/lib/libImath-2_2.12.dylib
Referenced from: /usr/local/Cellar/opencv/3.4.1_4/lib/libopencv_imgcodecs.3.4.dylib
Reason: image not found
I then tried to re-install opencv with the step by step explanation of this site with which I successfully installed opencv for the first time.
- determine which version of opencv I have on my machine
After having written cd /usr/local/Cellar/opencv and ls I get: 3.4.1_4 3.4.3 3.4.3_1. So I conclude that the latest version on my machine is 3.4.3_1 which is in /usr/local/Cellar/opencv/3.4.3_1/cv2.cpython-37m-darwin.so
- Determine the path for package in python
Then if i do the following $ cd /usr/local/Cellar/opencv/3.4.3_1 and $ cd lib, I get (among others): python3.7.
Then I do the following:
$ cd python3.7 and then $ cd site-packages and $ pwd, I get: /usr/local/Cellar/opencv/3.4.3_1/lib/python3.7/site-packages
- add the cv2.<version>.so to System python
I enter then python with $ python3 and get
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 03:03:55)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Question N°1 Isn't it weird that it says version 3.6.5 and opencv seems to have a lib 3.7 (and no 3.6)
type >>> import sys and then >>> print(sys.path)and get the following list:
['', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']
I then enter:
$ ln -s /usr/local/Cellar/opencv/3.4.3_1/lib/python3.7/site-packages/cv2.cpython-37m-darwin.so /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cv2.so
- Add OpenCV to Virtualenvs
I then add the following command:
$ mkdir ~/Dev
$ cd ~/Dev
$ virtualenv -p python3 newcvtest
$ cd newcvtest
$ source bin/activate
(newcvtest) $ python --version
Python 3.6.5
$ pip install numpy
$ cd lib/python3.6/site-packages
$ ln -s /usr/local/Cellar/opencv/3.4.3_1/lib/python3.7/site-packages/cv2.cpython-37m-darwin.so
After that the installation should be finished. However I still get the same error message
What should I do?
For python 3 only. Always used
pip3,python3thanks @supra56. I changed the tags accordingly
One thing is install library... libImath-2_2.12.dylib. Are you on pc or raspberry pi?
I'm on a mac. I found that it has probably to do with the fact that there are different version of python installed in my machine and that they have packages installed at different places. See: https://stackoverflow.com/questions/5...