To install CUDA Toolkit 12.1 in an Anaconda environment, follow these steps:
It’s a good practice to create a new environment to avoid version conflicts:
conda create --name cuda_env python=3.8
Replace cuda_env with the desired environment name and 3.8 with your preferred Python version.
You can install CUDA Toolkit 12.1 using the conda package manager. NVIDIA has made this available via the nvidia channel.
Run the following command:
conda install -c nvidia cuda-toolkit=12.1
This command installs the CUDA Toolkit 12.1 along with the necessary dependencies, such as the NVIDIA driver and cuDNN.
Once installed, you can check the CUDA version by running:
Alternatively, you can check if CUDA is properly configured within Python using PyTorch or TensorFlow:
For PyTorch:
print(torch.cuda.is_available())
print(torch.version.cuda)
For TensorFlow:
print(tf.config.list_physical_devices('GPU'))
If these commands run without issues, CUDA is successfully installed in your Anaconda environment.
If you plan to use CUDA for machine learning libraries like PyTorch or TensorFlow, install the GPU versions of these libraries.
For PyTorch:
conda install pytorch torchvision torchaudio cudatoolkit=12.1 -c pytorch -c nvidia
For TensorFlow:
pip install tensorflow-gpu
You now have CUDA Toolkit 12.1 set up and ready for use in your Anaconda environment.