前置き
今回は強化学習のフレームワークのKeras-RLを使用するために,TensorFlowの1.14.0をインストールしたいと思います.
環境
- OS: Mac OS Mojave 10.14.6
- 言語 : Python 3.7,3.8
インストール
通報のインストールの場合
terminal
$ pip install tensorflow
バージョン指定する場合
terminal
$ pip install tensorflow==1.14.0
しかし以下のようなエラーが出る場合があります.
terminal
$ pip install tensorflow==1.14.0
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
TensorFlow公式サイトをみながら対処しましたが,自分の場合は解決に至らず...
(イメージの配布もTensorFLow 2.Xしかなさそう...?)
TensorFlowのバージョンによってPythonバージョンの制約もあるので確認しましょう.
解決法
以下の2つで解決できました.
1. イメージファイルのURLを直打ちする
terminal
$ pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.14.0-py3-none-any.whl
2. pyenv を使用する
pyenvとは
pyenvとはPythonの複数のバージョンを使い分けるコマンドラインツールで、RubyのrbenvやNodeJSのnvmのようなバージョン管理ツールです。これを作ったのは日本の方のようで、すごいですね。これを使えば案件ごとにpythonのバージョンを細かく決められるので、とても便利に使えます。
pyenvのインストールについてはこちらの記事が参考になります.
pyenvを使ってMacにPythonの環境を構築する
また,上記記事の前に公式記載のPrerequistesのinstallをお忘れなく!!
pyenvでTensorFlow1.14対応のPython3.7をインストールしてみます.
terminal
$ pyenv install 3.7.2
次にpipでTensorFlowをインストールします.
terminal
pip install tensorflow==1.14.0
これで無事インストールできました.