9951 explained code solutions for 126 technologies


python-pytorchHow do I install PyTorch with CUDA using Python?


  1. First, you need to install PyTorch with CUDA support. This can be done with the following command:
pip install torch torchvision
  1. After installation, you need to check if PyTorch is installed with CUDA support. This can be done with the following command:
python -c "import torch; print(torch.cuda.is_available())"

The output of this command should be True if PyTorch is installed with CUDA support.

  1. After installation, you need to set up the environment variables for CUDA. This can be done with the following command:
export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  1. You then need to check if the environment variables are set correctly. This can be done with the following command:
echo $PATH
echo $LD_LIBRARY_PATH

The output of these commands should include the paths that were set in step 3.

  1. Finally, you need to check if PyTorch is using the correct CUDA version. This can be done with the following command:
python -c "import torch; print(torch.version.cuda)"

The output of this command should be the version of CUDA that you installed in step 1.

## Helpful links

Edit this code on GitHub