If you use Anaconda, it is best to create a dedicated environment first. : conda create -n my_env python=3.11 Activate Environment : conda activate my_env
If you see a grid of random numbers (a tensor) and no errors, your installation was successful. Troubleshooting Common Issues
: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126 For macOS : pip3 install torch torchvision Option B: Using Conda (Recommended for Data Science)
Open your Command Prompt (Windows) or Terminal (macOS/Linux) and run the command that matches your setup.
: Determine if you will use your CPU or an NVIDIA GPU (which requires CUDA support for acceleration). 2. Choose Your Installation Method
import torch # Check version print(torch.__version__) # Check if GPU is detected (should return True if using CUDA) print(torch.cuda.is_available()) # Create a test tensor x = torch.rand(5, 3) print(x) ``` Use code with caution.
To download and install (also known as PyTorch ), you must use a package manager like pip or conda rather than downloading a standalone installer file. The exact command varies based on your operating system, whether you have an NVIDIA GPU, and which Python version you are using. 1. Check Prerequisites
: pip install torch torchvision torchaudio
: PyTorch 2.0+ requires Python 3.10 to 3.14 . Check your version by typing python --version in your terminal.