Python is one of the most popular and widely used high-level interpreted languages known for its ease of use and readability. Python is available for Windows, Linux, and macOS, making it a versatile tool for any computer user, But most people get confused and stuck when it comes to installation. So, In this article, we will show you how to install Python on Windows, Linux, and macOS. We will also show you how to configure your development environment and start writing your first Python code.
How to Install Python on windows:
Way 1: Installing it manually
- Head to the official website of Python (python.org/download) and download the latest version for windows.
- After downloading, open the executable (.exe) file. It will take us to the python installation setup.
- On the installation setup, Check the box “Add python.exe to PATH” and Choose “customize installation.”
- On the optional feature tab, all the checkboxes are checked by default. If not, then Check all the boxes and click next.
- On the Advanced options, Check the first box, “Install python for all users,” customize the installation path as you like, and then click on the install button.
That’s it. We have successfully installed Python’s latest version on our windows operating system.
Way 2: Install Python from the Microsoft Store
The Microsoft Store is the best place to get Python if you’re a beginner. It’s quick and easy to install, and you don’t need to set up any external tools.
To install Python from the Microsoft Store:
- Open the Microsoft Store and search for “Python.”
- Click on the Python 3. x (Make sure to download the latest version) app.
- Click Install.
That’s it. Once the installation is complete, you can launch Python from the Start menu.
Using Python on command prompt:
Yes, We have installed Python on our windows machine. Let’s open it via the command prompt to check whether it is working properly and to write our first code.
- To open the command prompt, press the win key + R, type “cmd,” and then press “enter key” or click the start menu and search for “command prompt.”
- To check the version, type the command ‘python –version.’
- To open the python interpreter and type our first code, type ‘python’ on the command prompt.
- Hooray! We have successfully opened our python interpreter. Now it’s time to code; type your desired code.
Using python IDLE Shell:
IDLE stands for Integrated Development and Learning Environment. This IDLE shell comes default with python installation so that we can type and run our code here. Now, let’s see how to open the python IDLE shell and write our code.
- To open the python IDLE shell, click the start menu and type “IDLE.”
- That’s it. We are good to go. Type your first code.
So far, we have been using the single-line python interpreter(i.e., we can’t type more than 1 line). To type a whole program/script, Click on the file -> New.
Doing this will open up a new file for us to type. Our playground is now ready! Write the script, save and run it.
How to Install Python on Linux
There are different ways to install Python on Linux. The most common way is to use a package manager such as apt-get, yum, etc. Alternatively, you can download the Python source code and install it manually.
Way 1: Installing Python using a package manager
You can install Python using your package manager with the help of these commands.
On Debian-based distributions such as Ubuntu, you can use the apt package manager to install Python 3 like this:
sudo apt-get install python3
On Fedora, you can use the dnf package manager to install Python 3 like this:
sudo dnf install python3
On Red Hat, you can use the yum package manager to install Python 3 like this:
sudo yum install python3
On SUSE, you can use the zypper package manager to install Python 3 like this:
sudo zypper install python3
You may also like: Basic Linux commands – part one
Way 2: Installing Python manually on Linux
The first thing you need to do is download the Python installer from the Python website. Be sure to choose the Operating system Linux and the installer for Python 3. x, as Python 2. x has reached end-of-life and is no longer supported.
Once the download is complete, open a terminal and navigate to the directory where you downloaded the installer. Then, run the following command:
sudo sh Python-3.x.x.tgz(Here, x.x refers to the version number)
This command will extract the files from the installer and install them on your system.
How to Install Python on Mac
macOS comes with Python 2.7 installed by default. However, this version is outdated and no longer supported by the Python community. Therefore, we will install Python 3.
There are two ways to install Python 3 on your Mac. Like Linux, you can use a package manager such as Homebrew to install Python 3 or manually download and install it from the python website.
Way 1: Using package manager
Here is the command to install Python using the homebrew package manager,
brew install python3
The installation process will take a few minutes to complete.
If you don’t have Homebrew installed on your Mac, install Homebrew first and then use it to install Python 3.
Verifying the Installation:
Once the installation is complete, you can verify it by entering the following command:
This command should return the version of Python installed, such as Python 3.11.1.
If you see an error message instead of the Python version number, Python is not correctly installed. In this case, try uninstalling and then reinstalling Python using Homebrew.
Way 2: Installing Python 3 from the Python Website
Visit the Python downloads page and download the macOS installer’s latest version of Python 3, which at the time of posting this article is 3.11.1.
Once the download is complete, open the file and follow the on-screen instructions to install Python 3 on your computer.
After the installation, we can test that Python is working properly by opening up the Terminal application and typing “python3”. This command should bring up the Python interpreter, and we can then type in some code to ensure everything is working.
This blog post has shown how to install Python on three different platforms: Windows, Linux, and Mac OS. Each platform has its own set of instructions, so be sure to follow the steps for your specific system. Once Python is installed, you can start using it to develop programs and scripts.
Make sure to comment below if you face any difficulties downloading Python; we will try to help you. Subscribe to our newsletter to receive a notification whenever we add a new blog post. See you all in the following article. Cheers!