hachiNote

勉強したことをメモします。

MacにpyenvでAnacondaをインストールしたときのバージョンメモ

目的

ほぼ皆様には特に何の得にもならない情報だと思いますが、MacでpyenvでAnacondaの各種バージョンを入れときに、そのまま conda で TensorFlowとKerasをインストールしたら、バージョンは何が入るのかをメモしておきます。

もちろん、自分でバージョンをちゃんと指定したりしてインストールすればなんかちゃんと自分の思い通りにできるのかとは思うんですが、そこまで理解が追いついていないのでただのメモです。

環境は macOS Catalina バージョン10.15.7、pyenvはhomebrewで入れた状態です。

インストール可能なAnacondaのバージョンの確認

以前Anacondaをインストールした時は、anaconda3-5.2.0 のようなバージョン名だったので、「5より新しいやつがあるのかな」みたいな気持ちでインストール可能なバージョンを確認してみた。

% pyenv install --list
(中略)
  anaconda3-4.4.0
  anaconda3-5.0.0
  anaconda3-5.0.1
  anaconda3-5.1.0
  anaconda3-5.2.0
  anaconda3-5.3.0
  anaconda3-5.3.1
  anaconda3-2018.12
  anaconda3-2019.03
  anaconda3-2019.07
  anaconda3-2019.10
  anaconda3-2020.02
  anaconda3-2020.07
(略)

うん? 5.3.1で止まっているように見える。 anaconda3-2020.07 みたいなバージョンとどういう関係性なんだろう?

Anacondaのリポジトリを見てみると、なんとなく分かった気がする。

repo.anaconda.com

Last Modifiedの日付を見る限り、前はanaconda3-5.3.0のような表記で、途中でバージョンの表記ルールが変わったということのようだ。日付が連続していて重複がないので。

ということは、anaconda3-2020.07 がこの時(2020年10月時点)の最新らしい。

anaconda3-2020.07をインストールしたとき

% pyenv install anaconda3-2020.07
Downloading Anaconda3-2020.07-MacOSX-x86_64.sh...
-> https://repo.continuum.io/archive/Anaconda3-2020.07-MacOSX-x86_64.sh
Installing Anaconda3-2020.07-MacOSX-x86_64...
Installed Anaconda3-2020.07-MacOSX-x86_64 to /Users/xxx/.pyenv/versions/anaconda3-2020.07
% pyenv rehash
% pyenv local anaconda3-2020.07

無事入った。なお、pyenvでanaconda(あるいは普通のpython)をインストールした後は 上記のようにrehashとlocalを打っているが、もちろんlocalじゃなくてglobalでもいい。自分の好みに合わせてください。rehashは打たないとインストールしたpythonが使えなかったので必要っぽい雰囲気。

anaconda3-2020.07によってインストールされたpythonは以下のようにバージョンは3.8.3のようだ。

% python --version
Python 3.8.3

ではtensorflowとkerasをcondaでインストールしてみる。まずはtensorflowから。

% conda install tensorflow
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: - 
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed                                                                                                                                         

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - tensorflow -> python[version='2.7.*|3.7.*|3.6.*|3.5.*']

Your python: python=3.8

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

どうもバージョンが合わないって言われているようだ。回避方法とかあるのかもしれないが、深く追うつもりはなかったのでさっさと諦めてもう少し古いバージョンのAnacondaを入れてみることにする。

anaconda3-2020.02をインストールしたとき

さっきのメッセージによると3.7.xなら良いようなので、3.7.xが入るanacondaを探すと 2020.02 ならそうっぽい。ということで入れてみる。

% pyenv install anaconda3-2020.02
Downloading Anaconda3-2020.02-MacOSX-x86_64.sh...
-> https://repo.continuum.io/archive/Anaconda3-2020.02-MacOSX-x86_64.sh
Installing Anaconda3-2020.02-MacOSX-x86_64...
Installed Anaconda3-2020.02-MacOSX-x86_64 to /Users/xxx/.pyenv/versions/anaconda3-2020.02
% pyenv rehash
% pyenv local anaconda3-2020.02

入った。ではtensorflowとkerasをインストールしてみる。

% conda install tensorflow
% conda install keras

今度はエラーにならずに両方入った。コマンドライン上で各バージョンを確認してみる。

% python
Python 3.7.6 (default, Jan  8 2020, 13:42:34) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Using TensorFlow backend.
>>> print(keras.__version__)
2.3.1
>>> import tensorflow as tf
>>> print(tf.__version__)
2.0.0

うん、良さそう。が、TensoFlowが2.0.0になっているのが気になった。 TensorFlowは1.xと2.xで書き方が結構違うという情報があったので(実際既に用意していたスクリプトはエラーになった。placeholderとか使えないらしい)、pyenvで環境を用意している利点を生かして、TensorFlow 1.xがインストールされている環境も作っておこう。

anaconda3-2019.07をインストールしたとき

conda install tensorflow のときにバージョン指定すれば任意のバージョンが入れられそうではあるが、横着で単にAnacondaのバージョンをさらに古くする作戦に出る。

さらに古いやつということで、anaconda3-2019.10をインストールして conda install tensorflow してみたが、入ったTensorFlowは2.0.0だった。

ということでさらに古いanaconda3-2019.07を入れてみる。

% pyenv install anaconda3-2019.07
Downloading Anaconda3-2019.07-MacOSX-x86_64.sh...
-> https://repo.continuum.io/archive/Anaconda3-2019.07-MacOSX-x86_64.sh
Installing Anaconda3-2019.07-MacOSX-x86_64...
Installed Anaconda3-2019.07-MacOSX-x86_64 to /Users/xxx/.pyenv/versions/anaconda3-2019.07
% pyenv rehash
% pyenv local anaconda3-2019.07
% conda install tensorflow
% conda install keras
% python
Python 3.7.3 (default, Mar 27 2019, 16:54:48) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Using TensorFlow backend.
>>> print(keras.__version__)
2.3.1
>>> import tensorflow as tf
>>> print(tf.__version__)
1.14.0

お望みどおり、1.xが入った。

まあ繰り返しますが、ちゃんと自分で好みのバージョンを指定してインストールすればいいだけのような気がしますが、調べるのが面倒だったので、Anacondaのバージョンを変えるという横着なことをしたときの記録でした。