walkingmask’s development log

IT系の情報などを適当に書いていきます

MENU

Mac OS X El CapitanにTensorFlowをpipで入れるときの落とし穴

追記 2016/05/16
久々にこの記事の環境でtensorflowを動かそうとしたらできなかったので,virtualenvで環境を再構築しました.pipよりずっと楽なのでこちらがオススメです.
walkingmask.hatenablog.com



TensorFlow触りたいね!機械学習したいね!けど英語わからなくてチュートリアルさえまともに読めなくて...とりあえず英語勉強しつつ日本語のWebページとか見ながら触っていこうと思う.

ってことで,とりあえず何でもいいからTensorFlowインストールしとこうとしたらエルキャピちゃんのせいでハマった落とし穴をlog.

環境

Mac OS X El Capitan(10.11.1)
Python 2.7.10
pip 7.1.2

落とし穴 (Pitfall)

公式のDownload and Setupに従ってpipでインストールしようとしたらハマった.

% pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl                                    
Collecting tensorflow==0.5.0 from https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
  Using cached https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
Collecting six>=1.10.0 (from tensorflow==0.5.0)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting numpy>=1.9.2 (from tensorflow==0.5.0)
  Using cached numpy-1.10.1-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Installing collected packages: six, numpy, tensorflow
  Found existing installation: six 1.4.1
    DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/basecommand.py", line 211, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/commands/install.py", line 311, in run
    root=options.root_path,
  File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/req/req_set.py", line 640, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/req/req_install.py", line 716, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/req/req_uninstall.py", line 125, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/utils/__init__.py", line 315, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
    copy2(src, real_dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
    copystat(src, dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
    os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/98/f5yhj5k51r18qfgxm8xx83v40000gn/T/pip-s4Fqnv-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

結論から言うと,OS Xに最初から入ってるPythonが原因だった./usr/bin/pythonに入ってるやつ.

which python
/usr/bin/python

最初からPythonが入ってるのはいいことなんだけど,/usr/bin/に入ってるせいで色々問題があるよう.

抜け出した方法

以下,解決に至った方法.

pipのアンインストール

必要なかったかもしれないけど.まずはパッケージの全削除.
pipでインストールしたモジュールを全て削除 - Qiita
次にpip本体を削除.
easy_installでインストールしたパッケージ (pip) のアンインストール方法 - TASK NOTES

HomebrewでPythonを入れる

pipも付いてくる.

brew update
brew install python 
pip install --upgrade pip setuptools
brew linkapps python

Pythonのパスをシェルの設定に書いてあげる

例としてzsh

echo 'export PATH=/usr/local/bin:/usr/local/share/python:$PATH' >>~/.zshrc
source ~/.bash_profile

これで,

which python
/usr/local/bin/python

となってれば準備おk.あとは,pip install http://〜と実行してみれば多分抜けられる.

参考にさせていただいたWebページ

MacOSX Mavericks(10.9)にhomebrewを使ってDjangoの開発環境を整える - Qiita
(2015/11/16)