Would you like to learn how to download a file using Python? In this tutorial, we are going to show you how to download a file using Python on a computer running Linux.

• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• Python 3.8.5
• Python 2.7.18

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial Python 3 – Downloading a file

Download a file using Python.

Copy to Clipboard

In our example, we downloaded the official Firefox installer.

In our example, we saved the Firefox installer inside the TMP directory.

In our example, we saved the Firefox installer using the name FirefoxInstaller.exe.

In our example, we used the binary mode.

Keep in mind that you need to change the URL and file name.

Access the directory and verify if the file was downloaded correctly.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Optionally, download a file over HTTP using Python.

Copy to Clipboard

Congratulations! You are able to download files using Python.

Tutorial Python 2 – Downloading a file

Download a file using Python 2.

Copy to Clipboard

In our example, we downloaded the official Firefox installer.

In our example, we saved the Firefox installer inside the TMP directory.

In our example, we saved the Firefox installer using the name FirefoxInstaller.exe.

In our example, we used the binary mode.

Keep in mind that you need to change the URL and file name.

Access the directory and verify if the file was downloaded correctly.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Optionally, download a file over HTTP using Python 2.

Copy to Clipboard

Congratulations! You are able to download files using Python 2.