Last modified: Mar 25, 2025 By Alexander Williams
How to Install TensorFlow in Python Step by Step
TensorFlow is a popular library for machine learning. It helps build and train models. This guide will show you how to install it.
Table Of Contents
Prerequisites
Before installing TensorFlow, ensure you have Python installed. Python 3.7 to 3.10 is recommended. Check your Python version using python --version
.
# Check Python version
python --version
Python 3.8.5
If you don't have Python, download it from the official website. Also, ensure pip is installed. Pip is Python's package manager.
Install TensorFlow
TensorFlow can be installed using pip. Open your terminal or command prompt. Run the following command.
# Install TensorFlow
pip install tensorflow
This will download and install TensorFlow. It may take a few minutes. Wait for the installation to complete.
Verify Installation
After installation, verify TensorFlow is working. Open Python in your terminal. Import TensorFlow and check its version.
# Verify TensorFlow
import tensorflow as tf
print(tf.__version__)
2.6.0
If you see a version number, TensorFlow is installed. If not, check for errors. You might need to troubleshoot.
Common Installation Issues
Sometimes, you may face issues. One common error is ModuleNotFoundError. This means TensorFlow is not installed correctly.
If you see No module named 'tensorflow', reinstall TensorFlow. Follow the steps again. For more help, read our guide on How To Solve ModuleNotFoundError.
Install Specific TensorFlow Version
You may need a specific TensorFlow version. Use pip to install it. Specify the version number.
# Install specific version
pip install tensorflow==2.5.0
This installs TensorFlow 2.5.0. Replace the version as needed. Check the official site for available versions.
Install TensorFlow with GPU Support
For faster performance, use TensorFlow with GPU. Ensure you have a compatible GPU. Install the GPU version.
# Install TensorFlow GPU
pip install tensorflow-gpu
Note: You also need CUDA and cuDNN installed. Check TensorFlow's documentation for details.
Upgrade TensorFlow
To upgrade TensorFlow, use pip. Run the following command.
# Upgrade TensorFlow
pip install --upgrade tensorflow
This will install the latest version. Always check compatibility with your code.
Uninstall TensorFlow
To uninstall TensorFlow, use pip. Run the command below.
# Uninstall TensorFlow
pip uninstall tensorflow
Confirm the action when prompted. This removes TensorFlow from your system.
Conclusion
Installing TensorFlow is simple with pip. Follow the steps above to get started. Always verify the installation.
If you face issues, check the error messages. Reinstall or upgrade as needed. Now you're ready to build machine learning models.