TensorFlow 2 パッケージが利用可能
tensorflow
- 最新の安定版リリース、CPU および GPU サポート(Ubuntu、Windows 用)tf-nightly
- プレビュー ビルド(不安定)。Ubuntu 用と Windows 用には GPU サポートが含まれています。
旧バージョンの TensorFlow
TensorFlow 1.x では、CPU パッケージと GPU パッケージは次のように別個のものです。
tensorflow==1.15
- CPU のみのリリースtensorflow-gpu==1.15
- GPU サポートを含むリリース(Ubuntu、Windows 用)
システム要件
- Python 3.6~3.9
- Python 3.9 サポートには、TensorFlow 2.5 以降が必要です。
- Python 3.8 サポートには、TensorFlow 2.2 以降が必要です。
- pip 19.0 以降(
manylinux2010
サポートが必要) - Ubuntu 16.04 以降(64 ビット)
- macOS 10.12.6(Sierra)以降(64 ビット)、GPU サポートなし
- macOS には pip 20.3 以降が必要
- Windows 7 以降(64 ビット)
- GPU サポートには CUDA® 対応カードが必要(Ubuntu、Windows 用)
ハードウェア要件
- TensorFlow 1.6 以降、バイナリは AVX 命令を使用するので、古い CPU では動作しないことがあります。
- Ubuntu または Windows 上で CUDA® 対応の GPU カードをセットアップするには、GPU サポートのガイドをご確認ください。
1. Python 開発環境をシステムにインストールする
ご利用の Python 環境が構成済みかどうかを確認します。
python3 --version
pip3 --version
上記のパッケージがすでにインストールされている場合は、次の手順に進みます。
インストールされていない場合は、Python、pip パッケージ マネージャー、venv をインストールします。
Ubuntu
sudo apt update
sudo apt install python3-dev python3-pip python3-venv
macOS
Homebrew パッケージ マネージャーを使ってインストールします。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
# if you are on macOS 10.12 (Sierra) use `export PATH="/usr/local/bin:/usr/local/sbin:$PATH"`
brew update
brew install python # Python 3
Windows
Visual Studio 2015、2017 および 2019 用 Microsoft Visual C++ 再頒布可能パッケージをインストールします。TensorFlow 2.1.0 以降のバージョンでは、このパッケージに含まれる msvcp140_1.dll
ファイルが必要です。これは、古い再頒布可能パッケージでは提供されない場合があります。
この再頒布可能ファイルは Visual Studio 2019 に付属していますが、別々にインストールすることもできます。
- Microsoft Visual C++ のダウンロード サイトに移動します。
- Visual Studio 2015、2017、および 2019 のセクションまでスクロールします。
- プラットフォームに適した Visual Studio 2015、2017 および 2019 用 Microsoft Visual C++ 再頒布可能パッケージをダウンロードしてインストールします。
Windows で長いパスが有効になっていることを確認します。
Windows 用の Python 3 リリース、64 ビット版(オプション機能として pip
を選択)をインストールします。
その他
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
2. 仮想環境を作成する(推奨)
Python 仮想環境を使用して、パッケージのインストール先をシステムから分離します。
Ubuntu / macOS
新しい仮想環境を作成するには、Python インタプリタを選択し、それを保管する ./venv
ディレクトリを作成します。
python3 -m venv --system-site-packages ./venv
シェル固有のコマンドを使ってその仮想環境を有効化します。
source ./venv/bin/activate # sh, bash, or zsh
. ./venv/bin/activate.fish # fish
source ./venv/bin/activate.csh # csh or tcsh
仮想環境が有効になると、シェル プロンプトの先頭に (venv)
が付きます。
ホストシステムのセットアップに影響を及ぼさないよう、パッケージを仮想環境にインストールします。pip
のアップグレードから開始します。
pip install --upgrade pip
pip list # show packages installed within the virtual environment
仮想環境を後で終了する場合は、次のコマンドを実行します。
deactivate # don't exit until you're done using TensorFlow
Windows
新しい仮想環境を作成するには、Python インタプリタを選択し、それを保管する .\venv
ディレクトリを作成します。
python -m venv --system-site-packages .\venv
仮想環境を有効化します。
.\venv\Scripts\activate
ホストシステムのセットアップに影響を及ぼさないよう、パッケージを仮想環境にインストールします。pip
のアップグレードから開始します。
pip install --upgrade pip
pip list # show packages installed within the virtual environment
仮想環境を後で終了する場合は、次のコマンドを実行します。
deactivate # don't exit until you're done using TensorFlow
Conda
TensorFlow が提供する pip パッケージをおすすめしますが、コミュニティがサポートする Anaconda パッケージも利用できます。インストール方法については、Anaconda TensorFlow のガイドをご覧ください。
3. TensorFlow の pip パッケージをインストールする
以下の TensorFlow パッケージのいずれかを選択して、PyPI からインストールします。
tensorflow
- 最新の安定版リリース、CPU および GPU サポート(Ubuntu、Windows 用)。tf-nightly
- プレビュー ビルド(不安定)。Ubuntu 用と Windows 用には GPU サポートが含まれています。tensorflow==1.15
- TensorFlow 1.x 最終版。
仮想環境のインストール
pip install --upgrade tensorflow
インストールを検証します。
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
システムのインストール
pip3 install --user --upgrade tensorflow # install in $HOME
インストールを検証します。
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
パッケージの場所
一部のインストール方式では、TensorFlow の Python パッケージの URL が必要になります。 指定する URL はご利用の Python のバージョンによって異なります。
バージョン | URL |
---|---|
Linux | |
Python 3.6 GPU サポート | https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.6.0-cp36-cp36m-manylinux2010_x86_64.whl |
Python 3.6 CPU のみ | https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.6.0-cp36-cp36m-manylinux2010_x86_64.whl |
Python 3.7 GPU サポート | https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.6.0-cp37-cp37m-manylinux2010_x86_64.whl |
Python 3.7 CPU のみ | https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.6.0-cp37-cp37m-manylinux2010_x86_64.whl |
Python 3.8 GPU サポート | https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.6.0-cp38-cp38-manylinux2010_x86_64.whl |
Python 3.8 CPU のみ | https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.6.0-cp38-cp38-manylinux2010_x86_64.whl |
Python 3.9、GPU サポート | https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-2.6.0-cp39-cp39-manylinux2010_x86_64.whl |
Python 3.9、CPU のみ | https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.6.0-cp39-cp39-manylinux2010_x86_64.whl |
macOS(CPU のみ) | |
Python 3.6 | https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.6.0-cp36-cp36m-macosx_10_11_x86_64.whl |
Python 3.7 | https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.6.0-cp37-cp37m-macosx_10_11_x86_64.whl |
Python 3.8 | https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.6.0-cp38-cp38-macosx_10_11_x86_64.whl |
Python 3.9 | https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-2.6.0-cp39-cp39-macosx_10_11_x86_64.whl |
Windows | |
Python 3.6 GPU サポート | https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.6.0-cp36-cp36m-win_amd64.whl |
Python 3.6 CPU のみ | https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.6.0-cp36-cp36m-win_amd64.whl |
Python 3.7 GPU サポート | https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.6.0-cp37-cp37m-win_amd64.whl |
Python 3.7 CPU のみ | https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.6.0-cp37-cp37m-win_amd64.whl |
Python 3.8 GPU サポート | https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.6.0-cp38-cp38-win_amd64.whl |
Python 3.8 CPU のみ | https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.6.0-cp38-cp38-win_amd64.whl |
Python 3.9、GPU サポート | https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.6.0-cp39-cp39-win_amd64.whl |
Python 3.9、CPU のみ | https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.6.0-cp39-cp39-win_amd64.whl |