Verify System Requirements
- Ensure your Windows operating system supports TensorFlow. Generally, TensorFlow supports Windows 10 and later versions.
- Check that you have a compatible Python version installed (Python 3.7–3.10 are currently supported).
- Ensure you have a minimum of 500MB of disk space for TensorFlow and its dependencies.
Install Python and PIP
- If you don't have Python installed, download it from the official Python website.
- Ensure that you check the option to add Python to your system PATH during installation.
- After installation, verify it using the following command in the Command Prompt:
python --version
- Ensure PIP (Python Package Index) is installed by checking its version:
pip --version
Create a Virtual Environment
- Navigate to the directory where you intend to create your virtual environment.
- Create a virtual environment using the following command:
python -m venv tensorflow-env
- Activate your virtual environment:
tensorflow-env\Scripts\activate
Install TensorFlow
- Once your virtual environment is activated, install TensorFlow using pip:
pip install tensorflow
- Make sure to specify the version if you need a particular one, using a command like:
pip install tensorflow==2.9.0
Verify Installation
- Open a Python interpreter by typing
python
in your command prompt.
- Inside the Python shell, execute the following to verify TensorFlow installation:
import tensorflow as tf
print(tf.__version__)
- If TensorFlow is correctly installed, your version number should display without errors.
Optional: Install TensorFlow with GPU Support
- If you have a compatible NVIDIA GPU and want to leverage it, install the GPU version of TensorFlow by ensuring your system meets these prerequisites:
- Install the CUDA Toolkit from the official NVIDIA website.
- Install cuDNN (CUDA Deep Neural Network library) from NVIDIA.
- After installing CUDA and cuDNN, install the TensorFlow-GPU package using:
pip install tensorflow-gpu
- Verify GPU support in TensorFlow once installation is complete:
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
Congratulations! You have successfully installed TensorFlow on Windows.
- Remember to deactivate your virtual environment when you're done by typing
deactivate
in your command prompt.