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.
Related tutorial – Python
On this page, we offer quick access to a list of tutorials related to Python.
Tutorial Python 3 – Downloading a file
Download a file using Python.
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.
Here is the command output.
Optionally, download a file over HTTP using Python.
Congratulations! You are able to download files using Python.
Tutorial Python 2 – Downloading a file
Download a file using Python 2.
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.
Here is the command output.
Optionally, download a file over HTTP using Python 2.
Congratulations! You are able to download files using Python 2.