Install TensorFlow with pip
This guide is for the latest stable version of TensorFlow. For the preview build (nightly), please use the pip package named
tf-nightly. Refer to these tables for older TensorFlow version requirements. For TensorFlow 1.x users, please refer to the migration guide to upgrade to TensorFlow 2.
Here is a lookup table for the install commands. Scroll down for the step-by-step instructions.
The following GPU-enabled devices are supported:
- NVIDIA® GPU card with CUDA® architectures 3.5, 5.0, 6.0, 7.0, 7.5, 8.0 and higher. See the list of CUDA®-enabled GPU cards.
- For GPUs with unsupported CUDA® architectures, or to avoid JIT compilation from PTX, or to use different versions of the NVIDIA® libraries, see the Linux build from source guide.
- Packages do not contain PTX code except for the latest supported CUDA® architecture; therefore, TensorFlow fails to load on older GPUs when
CUDA_FORCE_PTX_JIT=1is set. (See Application Compatibility for details.)
- Ubuntu 16.04 or higher (64-bit)
- macOS 10.12.6 (Sierra) or higher (64-bit) (no GPU support)
- Windows 7 or higher (64-bit)
- Python 3.7–3.10
- pip version 19.0 or higher for Linux (requires
manylinux2010support) and Windows, version 20.3 or higher for macOS
- Windows Requires Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019
The following NVIDIA® software are only required for GPU support.
- NVIDIA® GPU drivers version 450.80.02 or higher.
- CUDA® Toolkit 11.2.
- cuDNN SDK 8.1.0.
- (Optional) TensorRT to improve latency and throughput for inference.
We only officially support Ubuntu. However, the following instructions may also work for other Linux distros.
We recommend using Miniconda to create a separate environment to avoid changing any installed software in your system. This is also the easiest way to install the required software, especially for the GPU setup.
You can use the following command to install Miniconda. During installation, you may need to press enter and type "yes".
You may need to restart your terminal or
source ~/.bashrc to enable the
conda command. Use
conda -V to test if it is installed successfully.
Create a conda environment
Create a new conda environment named
tf with the following command.
You can deactivate and activate it with the following commands.
Please make sure it is activated for the rest of the installation.
You can skip this section if you only run TensorFlow on CPU.
First, we need to install NVIDIA GPU driver if you have not. You can use the following command to verify it is installed.
Then, we install the CUDA, cuDNN with conda.
Configure the system paths. You can do it with following command everytime your start a new terminal after activating your conda environment.
However, for your convenience, we recommend automating it with the following commands. The system paths will be automatically configured when you activate this conda environment.
TensorFlow requires a recent version of pip, so upgrade your pip installation to be sure you're running the latest version.
Then, install TensorFlow with pip.
Verify the CPU setup:
If a tensor is returned, you've installed TensorFlow successfully.
Verify the GPU setup:
If a list of GPU devices is returned, you've installed TensorFlow successfully.
A few installation mechanisms require the URL of the TensorFlow Python package. The value you specify depends on your Python version.