OpenCVのインストールその2 | Visualize the Invisible

Visualize the Invisible

データとAIを使って、混沌とした世界を「見える化」したい。

AnacondaでPython + OpenCVを動かしたいが、なぜかエラー。

時間がもったいないのであきらめる。Anacondaを使わないで
Python + OpenCVを動かす方法を検討。


pythonのプロンプトから抜けるのはCtrl+D

思うに、Pythonはデフォルトで
sh-3.2# which python
/System/anaconda/bin/python
を参照。

一方で、openCVは
/usr/local/Cellar/opencv3/3.1.0_3: 282 files, 120.9M, built in 5 minutes 26 seconds

sh-3.2# 


そのため、Python3.5をbrewでインストールし直した。

その後、brewでopencvからopencv3にlinkを張り直した。
sh-3.2# brew link opencv3 --force
Linking /usr/local/Cellar/opencv3/3.1.0_3... 
Error: Could not symlink bin/opencv_annotation
Target /usr/local/bin/opencv_annotation
is a symlink belonging to opencv. You can unlink it:
  brew unlink opencv

To force the link and overwrite all conflicting files:
  brew link --overwrite opencv3

To list all files that would be deleted:
  brew link --overwrite --dry-run opencv3
sh-3.2# brew unlink opencv --force
Unlinking /usr/local/Cellar/opencv/2.4.13... 67 symlinks removed
sh-3.2# brew link opencv3 --force
Linking /usr/local/Cellar/opencv3/3.1.0_3... 57 symlinks created
sh-3.2# 
sh-3.2# virtualenv -p /usr/local/bin/python3.4 ~/venv
The executable /usr/local/bin/python3.4 (from --python=/usr/local/bin/python3.4) does not exist
sh-3.2# virtualenv -p /usr/local/bin/python3.5 ~/venv
Running virtualenv with interpreter /usr/local/bin/python3.5
Using base prefix '/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5'
New python executable in /var/root/venv/bin/python3.5
Not overwriting existing python script /var/root/venv/bin/python (you must use /var/root/venv/bin/python3.5)
Installing setuptools, pip, wheel...done.
sh-3.2# cd ~/venv/lib/python3.5/site-packages
sh-3.2# ln -s /usr/local/Cellar/opencv3/3.0.0/lib/python3.5/site-packages/cv2.so ./
ln: .//cv2.so: File exists

sh-3.2# 


て、以下のように指定して起動。

sh-3.2# /usr/local/bin/python3.5
Python 3.5.1 (default, Apr 18 2016, 11:55:04) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.1.0'

>>> 

いったんここまで。