ITの隊長のブログ

ITの隊長のブログです。Rubyを使って仕事しています。最近も色々やっているお(^ω^ = ^ω^)

Macにanacondaをインストール

スポンサードリンク

機械学習を勉強し始めたので、便利と噂のanacondaをインストールしました。

$ pyenv install anaconda-2.1.0

# 環境をanacondaへ切り替え
$ pyenv global anaconda-2.1.0

んで、このサイトさんを参考にしました。

omoshetech.com

ついでOpenCVも入れようかなと思いました。が。

$ conda install -c https://conda.binstar.org/menpo opencv
-bash: conda: command not found

おろ?

どうやらパスがダメっぽい。フルパスで実行

$ ~/.pyenv/versions/anaconda-2.1.0/bin/conda install -c https://conda.binstar.org/menpo opencv

Fetching packages ...
conda-3.18.4-p 100% |##################################################################################################################################| Time: 0:00:00 195.84 kB/s
conda-env-2.4. 100% |##################################################################################################################################| Time: 0:00:00 120.79 kB/s
numpy-1.10.1-p 100% |##################################################################################################################################| Time: 0:00:03 907.05 kB/s
opencv-2.4.11- 100% |##################################################################################################################################| Time: 0:00:04   2.05 MB/s
openssl-1.0.2d 100% |##################################################################################################################################| Time: 0:00:02   1.18 MB/s
python-2.7.10- 100% |##################################################################################################################################| Time: 0:00:04   2.30 MB/s
pyyaml-3.11-py 100% |##################################################################################################################################| Time: 0:00:00 169.71 kB/s
requests-2.8.1 100% |##################################################################################################################################| Time: 0:00:01 433.23 kB/s
sqlite-3.8.4.1 100% |##################################################################################################################################| Time: 0:00:01 527.60 kB/s
tbb-4.3_201410 100% |##################################################################################################################################| Time: 0:00:03 530.94 kB/s
tk-8.5.18-0.ta 100% |##################################################################################################################################| Time: 0:00:02 932.02 kB/s
yaml-0.1.6-0.t 100% |##################################################################################################################################| Time: 0:00:00 133.04 kB/s
zlib-1.2.8-0.t 100% |##################################################################################################################################| Time: 0:00:00 130.22 kB/s
Extracting packages ...
[      COMPLETE      ] |####################################################################################################################################################| 100%
Unlinking packages ...
[      COMPLETE      ] |####################################################################################################################################################| 100%
Linking packages ...
[      COMPLETE      ] |####################################################################################################################################################| 100%

おっ。めっちゃインストールされた!

サイトにならい、インストールされているか確認する。

$ python
Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] 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: No module named cv2
>>>  import cv2
  File "<stdin>", line 1
    import cv2
    ^

あり?

パスかな?

色々探っていると、やっぱりパスを追加しました。

$ export PATH="$HOME/.pyenv/shims:$PATH"

$ python
Python 2.7.10 |Anaconda 2.1.0 (x86_64)| (default, Oct 19 2015, 18:31:17) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import cv2
>>> cv2.__version__
'2.4.11'

うむ!

ちなみに、パスを追加する一行は~/.bash_profileにも追加しておきました。これでおk.