Installing PyTorch on Windows and Linux
Learn how to install PyTorch on Windows and Linux.
To install and use PyTorch, we need to properly set up the Python development environment first. So, in this section, we will first talk about how to set up the Python environment, then how to install PyTorch either with official release binaries or by building from source. At the end of this section, we will introduce a lightweight yet extremely powerful code editor tool, Microsoft VS Code, and show how to configure it for PyTorch programming.
Setting up the Python environment
In the following sections, we will walk through how to set up the Python environment and how to install or build PyTorch on Windows 10 and Ubuntu. We assume that CUDA is installed on the system.
Installing Python
On Windows 10, download the Windows x86-64 executable installer. We may install any version we want. We’ll install the latest version (at the time of writing) as an example. The downloaded file is about 25 MB. Keep the default settings during installation, except that we could change the installation path to an easier-to-find location that is, C:\Python3
.
Make sure to check the box for Add Python 3.x to PATH during installation; otherwise, we’ll have to add the environment variables manually: C:\Python3\
and C:\Python3\Scripts\
. The detailed process of adding environment variables on Windows 10 is described later in this section.
On Ubuntu, some versions of Python have already been shipped with the system. So, we don’t have to do anything for now.
On Ubuntu, if we plan on using the default version of Python provided by the system, think twice before we modify it (including upgrading, downgrading, or uninstalling) because it will affect many other things in our system. Always make sure we are using the right version of Python. Sometimes, installing and using packages across Python can be a little bit messy.
Installing Anaconda Python
On Windows 10, download the installer from
At the end of the installation, we will be asked whether we want to install the Microsoft VS Code. We recommend installing one for Python development. On Ubuntu, download the installer from ~/Downloads
):
Get hands-on with 1200+ tech skills courses.