Codementor Events

step-by-step guide starting from installing Python, TensorFlow, and CUDA on Windows:

Published Dec 12, 2024
step-by-step guide starting from installing Python, TensorFlow, and CUDA on Windows:

Step 1: Install PythonDownload Python:

Go to the Python Downloads Page.

Download Python 3.10 or 3.11 (compatible with TensorFlow and CUDA). python 3.13 is not compatible check documentation

Install Python:

Run the installer.

Select Add Python to PATH during installation.

Use the Customize installation option to include all features.

Verify Python Installation:
Open Command Prompt and type:bashCopy codepython --version
pip --version

Step 2: Create a Virtual EnvironmentSet Up a Virtual Environment:
Open Command Prompt and run:type:python -m venv tensorflow_env
Activate the environment:tensorflow_env\Scripts\activate

Upgrade pip:
Inside the virtual environment, upgrade pip:pip install --upgrade pip

Step 3: Install TensorFlowInstall TensorFlow with GPU Support:
Inside the virtual environment, install TensorFlow:pip install tensorflow

Verify TensorFlow Installation:
Check if TensorFlow is installed and GPU support is available:python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

If no GPUs are listed, proceed to the next step to install CUDA.
Step 4: Install CUDA ToolkitFind the Required CUDA Version:

Visit the TensorFlow GPU Support Page.

Find the compatible CUDA version for your TensorFlow version (e.g., TensorFlow 2.12 requires CUDA 11.8).

Download CUDA Toolkit:

Go to NVIDIA CUDA Toolkit Downloads.

Select your OS (Windows) and download the required CUDA version.

Install CUDA:

Run the CUDA installer and choose Express Installation.
After installation, verify by running:
Type this code:nvcc --version
Step 5: Install cuDNNDownload cuDNN:

Visit the NVIDIA cuDNN Page.

Log in or create a free account.

Download the cuDNN version matching your CUDA version.

Install cuDNN:

Extract the cuDNN ZIP file.
Copy the contents of bin, include, and lib folders into your CUDA installation directory, usually:makefileC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.x

Step 6: Configure Environment VariablesAdd CUDA Paths to Environment Variables:

Search for Environment Variables in the Windows search bar.

Under System Variables, edit the Path variable:
Add:makefileC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.x\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.x\libnvvp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.x\include
Restart Your PC:

Restart to apply the changes.
Step 7: Verify TensorFlow GPU SetupTest GPU in TensorFlow:
Run the following Python script to verify GPU is being used:import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
If the GPU is detected, TensorFlow is ready to us

Discover and read more posts from Ibikunle Samuel
get started