How to install latest TensorFlow version using PIP and Conda

This post explains how to install latest TensorFlow version using conda and pip.


Prerequisite

To follow the steps mentioned below, you need to have Anaconda distribution installed in your system, refer Anaconda installation steps to install Anaconda.


TensorFlow installation steps

Step 1: Create Python3.9 virtual environment with conda



conda create -n venv_py39 python=3.9


  

Step 2: Activate virtual environment



conda activate venv_py39


  

Step 3: Check Python and PIP version



python --version

# output
Python 3.9.6

pip --version

# output
pip 21.2.4


  

Step 4: Install the latest stable TensorFlow version with pip package



pip install --upgrade tensorflow


  

Step 5: Check TensorFlow version



python -c "import tensorflow as tf; print(tf.__version__)"

# output
2021-09-06 11:48:40.023881: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-09-06 11:48:40.033709: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

2.6.0


  

Step 6: Verify TensorFlow Installation



python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([100, 200])))"



  

If you getting tensor in output, than latest TensorFlow version is installed successfully. (Ignore the cudart related warnings)



2021-09-06 11:50:25.612224: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-09-06 11:50:25.622571: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-09-06 11:50:29.225694: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2021-09-06 11:50:29.234980: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2021-09-06 11:50:29.247104: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-LKK3I7H
2021-09-06 11:50:29.257000: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-LKK3I7H
2021-09-06 11:50:29.264401: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.

tf.Tensor(-91.322556, shape=(), dtype=float32)


  


Category: TensorFlow