9951 explained code solutions for 126 technologies


python-pytorchHow do I install PyTorch using pip in Python?


Installing PyTorch using pip is a straightforward process. Here are the steps to follow:

  1. Make sure you have Python installed on your system. You can check the version of Python installed by running the following command in the terminal:

python -V

  1. Install the latest version of pip by running the following command:

python -m pip install --upgrade pip

  1. Install PyTorch using the following command:

pip install torch torchvision

  1. Verify the installation by running the following command in the terminal:

python -c "import torch; print(torch.__version__)"

This should output the version of PyTorch installed.

  1. To install PyTorch for a specific version of Python, specify the version number in the command. For example, to install PyTorch for Python 3.7, use the following command:

pip3.7 install torch torchvision

  1. To install a specific version of PyTorch, specify the version number in the command. For example, to install version 1.3.1, use the following command:

pip install torch==1.3.1 torchvision==0.4.2

  1. To install PyTorch with GPU support, use the following command:

pip install torch torchvision cudatoolkit

Helpful links

Edit this code on GitHub