- Get Started
- Start Locally
- Installing on macOS
- Prerequisites
- macOS Version
- Python
- Package Manager
- Anaconda
- Installation
- Anaconda
- Verification
- Building from source
- Prerequisites
- Installing on Linux
- Prerequisites
- Supported Linux Distributions
- Python
- Package Manager
- Anaconda
- Installation
- Anaconda
- No CUDA
- With CUDA
- No CUDA
- With CUDA
- Verification
- Building from source
- Prerequisites
- Installing on Windows
- Prerequisites
- Supported Windows Distributions
- Python
- Package Manager
- Anaconda
- Installation
- Anaconda
- No CUDA
- With CUDA
- No CUDA
- With CUDA
- Verification
- Building from source
- Prerequisites
- Installing PyTorch 1.0 (Stable) with CUDA 10.0 on Windows 10 using Anaconda
- Step 1: Install NVIDIA CUDA 10.0 (Optional)
- Step 2: Install Anaconda with Python 3.7
- Step 3: Install PyTorch from the Anaconda Terminal
- Step 4: Install Intel MKL (Optional)
- Step 5: Choose your IDE
Get Started
Select preferences and run the command to install PyTorch locally, or get started quickly with one of the supported cloud platforms.
Start Locally
Select your preferences and run the install command. Stable represents the most currently tested and supported version of PyTorch. This should be suitable for many users. Preview is available if you want the latest, not fully tested and supported, 1.9 builds that are generated nightly. Please ensure that you have met the prerequisites below (e.g., numpy), depending on your package manager. Anaconda is our recommended package manager since it installs all dependencies. You can also install previous versions of PyTorch. Note that LibTorch is only available for C++.
Installing on macOS
PyTorch can be installed and used on macOS. Depending on your system and compute requirements, your experience with PyTorch on a Mac may vary in terms of processing time. It is recommended, but not required, that your Mac have an NVIDIA GPU in order to harness the full power of PyTorch’s CUDA support.
Currently, CUDA support on macOS is only available by building PyTorch from source
Prerequisites
macOS Version
PyTorch is supported on macOS 10.10 (Yosemite) or above.
Python
It is recommended that you use Python 3.5 or greater, which can be installed either through the Anaconda package manager (see below), Homebrew, or the Python website.
Package Manager
To install the PyTorch binaries, you will need to use one of two supported package managers: Anaconda or pip. Anaconda is the recommended package manager as it will provide you all of the PyTorch dependencies in one, sandboxed install, including Python.
Anaconda
To install Anaconda, you can download graphical installer or use the command-line installer. If you use the command-line installer, you can right-click on the installer link, select Copy Link Address , and then use the following commands:
If you installed Python via Homebrew or the Python website, pip was installed with it. If you installed Python 3.x, then you will be using the command pip3 .
Tip: If you want to use just the command pip , instead of pip3 , you can symlink pip to the pip3 binary.
Installation
Anaconda
To install PyTorch via Anaconda, use the following conda command:
To install PyTorch via pip, use one of the following two commands, depending on your Python version:
Verification
To ensure that PyTorch was installed correctly, we can verify the installation by running sample PyTorch code. Here we will construct a randomly initialized tensor.
The output should be something similar to:
Building from source
For the majority of PyTorch users, installing from a pre-built binary via a package manager will provide the best experience. However, there are times when you may want to install the bleeding edge PyTorch code, whether for testing or actual development on the PyTorch core. To install the latest PyTorch code, you will need to build PyTorch from source.
You will also need to build from source if you want CUDA support.
Prerequisites
- Install Anaconda
- Install CUDA, if your machine has a CUDA-enabled GPU.
- Follow the steps described here: https://github.com/pytorch/pytorch#from-source
You can verify the installation as described above.
Installing on Linux
PyTorch can be installed and used on various Linux distributions. Depending on your system and compute requirements, your experience with PyTorch on Linux may vary in terms of processing time. It is recommended, but not required, that your Linux system has an NVIDIA GPU in order to harness the full power of PyTorch’s CUDA support..
Prerequisites
Supported Linux Distributions
PyTorch is supported on Linux distributions that use glibc >= v2.17, which include the following:
- Arch Linux, minimum version 2012-07-15
- CentOS, minimum version 7.3-1611
- Debian, minimum version 8.0
- Fedora, minimum version 24
- Mint, minimum version 14
- OpenSUSE, minimum version 42.1
- PCLinuxOS, minimum version 2014.7
- Slackware, minimum version 14.2
- Ubuntu, minimum version 13.04
The install instructions here will generally apply to all supported Linux distributions. An example difference is that your distribution may support yum instead of apt . The specific examples shown were run on an Ubuntu 18.04 machine.
Python
Python 3.6 or greater is generally installed by default on any of our supported Linux distributions, which meets our recommendation.
Tip: By default, you will have to use the command python3 to run Python. If you want to use just the command python , instead of python3 , you can symlink python to the python3 binary.
However, if you want to install another version, there are multiple ways:
If you decide to use APT, you can run the following command to install it:
It is recommended that you use Python 3.6, 3.7 or 3.8, which can be installed via any of the mechanisms above .
If you use Anaconda to install PyTorch, it will install a sandboxed version of Python that will be used for running PyTorch applications.
Package Manager
To install the PyTorch binaries, you will need to use one of two supported package managers: Anaconda or pip. Anaconda is the recommended package manager as it will provide you all of the PyTorch dependencies in one, sandboxed install, including Python.
Anaconda
To install Anaconda, you will use the command-line installer. Right-click on the 64-bit installer link, select Copy Link Location , and then use the following commands:
You may have to open a new terminal or re-source your
/.bashrc to get access to the conda command.
While Python 3.x is installed by default on Linux, pip is not installed by default.
Tip: If you want to use just the command pip , instead of pip3 , you can symlink pip to the pip3 binary.
Installation
Anaconda
No CUDA
To install PyTorch via Anaconda, and do not have a CUDA-capable system or do not require CUDA, in the above selector, choose OS: Linux, Package: Conda and CUDA: None. Then, run the command that is presented to you.
With CUDA
To install PyTorch via Anaconda, and you do have a CUDA-capable system, in the above selector, choose OS: Linux, Package: Conda and the CUDA version suited to your machine. Often, the latest CUDA version is better. Then, run the command that is presented to you.
No CUDA
To install PyTorch via pip, and do not have a CUDA-capable system or do not require CUDA, in the above selector, choose OS: Linux, Package: Pip and CUDA: None. Then, run the command that is presented to you.
With CUDA
To install PyTorch via pip, and do have a CUDA-capable system, in the above selector, choose OS: Linux, Package: Pip and the CUDA version suited to your machine. Often, the latest CUDA version is better. Then, run the command that is presented to you.
Verification
To ensure that PyTorch was installed correctly, we can verify the installation by running sample PyTorch code. Here we will construct a randomly initialized tensor.
The output should be something similar to:
Additionally, to check if your GPU driver and CUDA is enabled and accessible by PyTorch, run the following commands to return whether or not the CUDA driver is enabled:
Building from source
For the majority of PyTorch users, installing from a pre-built binary via a package manager will provide the best experience. However, there are times when you may want to install the bleeding edge PyTorch code, whether for testing or actual development on the PyTorch core. To install the latest PyTorch code, you will need to build PyTorch from source.
Prerequisites
- Install Anaconda[#anaconda]
- Install CUDA, if your machine has a CUDA-enabled GPU.
- Follow the steps described here: https://github.com/pytorch/pytorch#from-source
You can verify the installation as described above.
Installing on Windows
PyTorch can be installed and used on various Windows distributions. Depending on your system and compute requirements, your experience with PyTorch on Windows may vary in terms of processing time. It is recommended, but not required, that your Windows system has an NVIDIA GPU in order to harness the full power of PyTorch’s CUDA support.
Prerequisites
Supported Windows Distributions
PyTorch is supported on the following Windows distributions:
The install instructions here will generally apply to all supported Windows distributions. The specific examples shown will be run on a Windows 10 Enterprise machine
Python
Currently, PyTorch on Windows only supports Python 3.x; Python 2.x is not supported.
As it is not installed by default on Windows, there are multiple ways to install Python:
If you use Anaconda to install PyTorch, it will install a sandboxed version of Python that will be used for running PyTorch applications.
If you decide to use Chocolatey, and haven’t installed Chocolatey yet, ensure that you are running your command prompt as an administrator.
For a Chocolatey-based install, run the following command in an administrative command prompt:
Package Manager
To install the PyTorch binaries, you will need to use at least one of two supported package managers: Anaconda and pip. Anaconda is the recommended package manager as it will provide you all of the PyTorch dependencies in one, sandboxed install, including Python and pip.
Anaconda
To install Anaconda, you will use the 64-bit graphical installer for PyTorch 3.x. Click on the installer link and select Run . Anaconda will download and the installer prompt will be presented to you. The default options are generally sane.
If you installed Python by any of the recommended ways above, pip will have already been installed for you.
Installation
Anaconda
To install PyTorch with Anaconda, you will need to open an Anaconda prompt via Start | Anaconda3 | Anaconda Prompt .
No CUDA
To install PyTorch via Anaconda, and do not have a CUDA-capable system or do not require CUDA, in the above selector, choose OS: Windows, Package: Conda and CUDA: None. Then, run the command that is presented to you.
With CUDA
To install PyTorch via Anaconda, and you do have a CUDA-capable system, in the above selector, choose OS: Windows, Package: Conda and the CUDA version suited to your machine. Often, the latest CUDA version is better. Then, run the command that is presented to you.
No CUDA
To install PyTorch via pip, and do not have a CUDA-capable system or do not require CUDA, in the above selector, choose OS: Windows, Package: Pip and CUDA: None. Then, run the command that is presented to you.
With CUDA
To install PyTorch via pip, and do have a CUDA-capable system, in the above selector, choose OS: Windows, Package: Pip and the CUDA version suited to your machine. Often, the latest CUDA version is better. Then, run the command that is presented to you.
Verification
To ensure that PyTorch was installed correctly, we can verify the installation by running sample PyTorch code. Here we will construct a randomly initialized tensor.
From the command line, type:
then enter the following code:
The output should be something similar to:
Additionally, to check if your GPU driver and CUDA is enabled and accessible by PyTorch, run the following commands to return whether or not the CUDA driver is enabled:
Building from source
For the majority of PyTorch users, installing from a pre-built binary via a package manager will provide the best experience. However, there are times when you may want to install the bleeding edge PyTorch code, whether for testing or actual development on the PyTorch core. To install the latest PyTorch code, you will need to build PyTorch from source.
Prerequisites
- Install Anaconda
- Install CUDA, if your machine has a CUDA-enabled GPU.
- If you want to build on Windows, Visual Studio with MSVC toolset, and NVTX are also needed. The exact requirements of those dependencies could be found out here.
- Follow the steps described here: https://github.com/pytorch/pytorch#from-source
You can verify the installation as described above.
Installing PyTorch 1.0 (Stable) with CUDA 10.0 on Windows 10 using Anaconda
PyTorch Anaconda Windows 10
This is a quick update to my previous installation article to reflect the newly released PyTorch 1.0 Stable and CUDA 10.
Step 1: Install NVIDIA CUDA 10.0 (Optional)
This is an optional step if you have a NVIDIA GeForce, Quadro or Tesla video card. Download the NVIDIA CUDA 10.0 Toolkit from the link below and install it. You can choose the network or local installer depending on your preference.
Step 2: Install Anaconda with Python 3.7
Anaconda is a great development environment that is supported across MacOS, Windows and Linux. I highly recommend this program. It makes it easy to install several Python code editors and PyTorch. My preferred editor is Spyder but Jupiter Notebook is also very popular and is used in a lot of the PyTorch challenge coursework. Download the file from the link below and install.
Additionally here are some Windows installation instructions from Anaconda if you run into any trouble.
Step 3: Install PyTorch from the Anaconda Terminal
Go to the Start Menu > Applications > Anaconda and open the Anaconda Prompt. Here you will run the following command to install PyTorch:
If you didn’t install CUDA and plan to run your code on CPU only, use this command instead:
Lastly I recommend updating all the modules and dependancies in Anaconda using the following command:
Press “Y” to start the update. It will take a few minutes to finish.
Step 4: Install Intel MKL (Optional)
If you have an Intel CPU, there are libraries you can install that speed up math processing routines. It’s best to install this after updating conda since the packages are specialized and can be older than the normal packages.
Step 5: Choose your IDE
Now load Anaconda and choose either Spyder or Jupiter Notebook. You can also check for updates by clicking the gear icon in the upper right hand corner of the application. If you have any issues or find any problems, feel free to leave a comment and I’ll update the post. Thanks and happy programming!