cBlog

Tips for you.

HomebrewとAnacondaの相性の悪さについて

スポンサーリンク
※当ブログのAmazon、iTunes、サウンドハウス等のリンクはアフィリエイトを利用しています。

オートメーション化したいことがあって、久しぶりにPythonを書いていました。いわゆる退屈なことはPythonにやらせよう、ですね。

退屈なことはPythonにやらせよう ―ノンプログラマーにもできる自動化処理プログラミング

退屈なことはPythonにやらせよう ―ノンプログラマーにもできる自動化処理プログラミング

 

ちなみにこの本、原著の英語版なら…全文が…ネットに…らしいです…

話を戻します。長いことコマンドラインなんかまともに触っていなかったのに、あるパッケージが必要になって久々にbrew doctor。激おこでした。

HomebrewとAnacondaが干渉するみたいです。warningの内容は取っておいていなかったけど、この記事に載っていたのが含まれていたと思う。一部引用させていただきます。

Pythonの開発環境を整える① - 暗号通貨.py

Warning: Anaconda is known to frequently break Homebrew builds, including Vim and
MacVim, due to bundling many duplicates of system and Homebrew-available
tools.
If you encounter a build failure please temporarily remove Anaconda
from your $PATH and attempt the build again prior to reporting the
failure to us. Thanks!

Warning: python is symlinked to python3
This will confuse build scripts and in general lead to subtle breakage.

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
//anaconda/bin/curl-config
//anaconda/bin/freetype-config
//anaconda/bin/libdynd-config
//anaconda/bin/libpng-config
//anaconda/bin/libpng16-config
//anaconda/bin/python3-config
//anaconda/bin/python3.5-config
//anaconda/bin/python3.5m-config
//anaconda/bin/xml2-config
//anaconda/bin/xslt-config
/usr/local/lib/libecomlodr.dylib

 

1つ目

Warning: Anaconda is known to frequently break Homebrew builds,

まじで?

Anacondaにパスが通らなくすればいいとのことですが、それもめんどくさいので.bash_profileを以下のように最上位になっていた優先度を下げることで解決しました。

export PATH="$PATH:$HOME/anaconda3/bin"

 

2つ目

こりゃ問題でしょうねえ。

1つ目のようにすればシステムのpythonが使われるようになるので解消しました。ただ、Python 3しか使わないのにいちいちpython3とタイプするのはつらいので以下のようにエイリアスを設定してみました。

alias py3='python3'

 

3つ目

以下の記事を参考に解消させることができました。

www.task-notes.com

エイリアスにより、正規表現を使ってbrewのときだけ$PATHから当該パスを取り除くというもの。

alias brew="env PATH=${PATH/${HOME}\/anaconda3\/bin:/} brew"

 

これでwarningはすべて消え、ready to brewになりました。

 

あとがき

pyenvからanacondaをインストールすれば大丈夫*1なような記述がありましたが、私の場合は変化ありませんでした。結局、Homebrew + 素のAnacondaに落ち着きました。おかげで何度もAnacondaをインストールし直すはめに*2。てか、Anaconda重いな… アップデートしたら1 Gくらい増えたぞ。

*1:加えて/usr/local/var/にインストールすることで

*2:brewとpyenvとcondaでわけわからん