osx El Capitan
I want to run OpenCV3 series and I want to use a new python. However, there are many things written for the OpenCV2 series, so I want to be able to run the OpenCV2 series as well. OpenCV2 series seems to work only with python2 series, so I want to make it possible to run multiple environments. So I decided to install pyenv and change the environment from there.
$ brew install pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(pyenv init -)"' >> ~/.zshrc
# python3.5.Install 1
$ pyenv install 3.5.1
Introduced from brew.
# brew install opencv3 --with-I tried hitting python3, but opencv3 is homebrew/science/I'm told to change to opencv3
$ brew install homebrew/science/opencv3 --with-python3
I put the above command from brew, but it doesn't work with the following error.
/tmp/opencv3-20161123-64293-17bmzya/opencv-3.1.0/modules/videoio/src/cap_qtkit.mm:46:9: fatal error: 'QTKit/QTKit.h' file not found
#import <QTKit/QTKit.h>
http://qiita.com/masaori/items/0c78fcd58a6c6bf4f655 This link says it happened on OS X Sierra, but it also happened on El Capitan. The solution is the same for now, get a new one by specifying HEAD in the brew option. Getting the HEAD may have mixed some other commits, but at this point there is no particular inconvenience.
$ brew install homebrew/science/opencv3 --with-python3 --HEAD
Make a symbolic link so that you can read the OpenCV so file via pyenv
$ ln -s /usr/local/Cellar/opencv3/HEAD-b8c875d_4/lib/python3.5/site-packages/cv2.cpython-35m-darwin.so ~/.pyenv/versions/3.5.1/lib/python3.5/site-packages
Check if it can be read properly from REPL below
$ python
Python 3.5.1 (default, Nov 7 2016, 22:30:16)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
At some point, the python2.7 module was loaded. Therefore, when you build OpenCV with brew, the so file is placed in / usr / local / opt / opencv3 / lib / python2.7 / site-packages /
, and even in the file, it is built on the premise of python2.7. Because of this, even if I put up a symbolic link, I got the following error and couldn't read it with python.
$ python
Python 3.5.1 (default, Nov 7 2016, 22:30:16)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/opt/opencv3/lib/python2.7/site-packages/cv2.so, 2): Symbol not found: _PyCObject_Type
Referenced from: /usr/local/opt/opencv3/lib/python2.7/site-packages/cv2.so
Expected in: flat namespace
in /usr/local/opt/opencv3/lib/python2.7/site-packages/cv2.so
>>>
Solve the module loading problem from here http://qiita.com/Asakage/items/690ce9048e708de41166
If you comment out the line in ~ / .local / lib / python3.5 / site-packages / homebrew.pth
, python3.5 will be loaded properly. It is unknown when this path was read. I set up pyvenv and did some things that weren't written here, so it may have happened at that time.
It takes a long time to build and various problems have occurred, so it may be the fastest to install OpenCV using conda.
Recommended Posts