Python is a popular programming language, and you may need to use it if you are into programming.
But before you use Python, you must install and configure it on your computer.
In this blog, we will discuss how to install Python on Windows, macOS, and Linux.
Install Python on Windows
Installing Python on Windows can be done in 4 steps:
- Select the Python version you want to install.
- Download the Python installer and run it.
- Verify Python installation.
- Verify PIP Installation.
Let's explore these installation steps further.
Step 1: Select Python Version to Install
Go to Python's official website and select the version you want to install. Different versions of Python 2 and Python 3 are available on the site.
If you are not sure about what you want to install, just select the latest version.
Step 2: Download the Python Installer and Run It
Then, download the Python installer of the version you have selected.
If you have a 64-bit Operating System, it won't matter which version you install. But for older 32-bit Operating Systems, make sure you install the 32-bit version of Python.
Run the installation file once you've completed your download. You will see this installation wizard.
Make sure you select the Add Python 3.10 to PATH button to avoid any hassle in the future.
If you want to do a custom installation, you can proceed with the second option. Else, select the Install Now button.
It will take some minutes to complete the installation. If installed successfully, you will see the "Setup was successful" screen.
Step 3: Verify Python Installation
We can verify the Python installation in two ways.
1. From Command Prompt
Search for Command Prompt in the Windows Start button. Then type python and press enter.
If Python has been installed successfully, you will see a version number on the terminal.
2. From Python Shell (IDE)
Search Python in the Windows Start menu and select the Python command line.
Then, to ensure it's working, let's write a simple print statement.
This is how it looks like in Python console:
You can use this Python terminal to run basic Python commands. However, you will need to use IDEs like Atom, Visual Studio Code, PyCharm, etc., to run large projects.
Step 4. Verify PIP Installation
After successfully installing Python, you can run your Python code through the terminal.
But you will need to use Python packages once you start building your projects. Thankfully, Python has a package manager called pip for exactly this purpose
You don't have to install pip separately as it comes installed by default. To ensure that pip is installed, type the pip -V command in the Command Prompt.
If you get the following screen, it means pip has been installed.
That's about it. You have successfully installed Python on Windows. Now, we will see how to install Python on Mac.
Install Python on Mac
If you have macOS, Python is already installed on your computer.
However, it has Python 2.7, which is not a compatible version to use today.
So, you have to update Python to the latest version on your Mac. You can do this in two ways:
- Installing Python with command line
- Installing Python with an online installer
We will also see how to verify the Python installation on Mac.
Install Python With the Command Line on Mac
Follow these steps to get Python through the command line.
Step 1: Install HomeBrew
HomeBrew is a package manager for macOS. To install Python, you first need to install HomeBrew.
Follow these steps:
- Open Terminal
- Go to Launchpad -> Other -> Terminal
- Install HomeBrew with the following commands
This will install HomeBrew, and you can now use it to install Python. If you face difficulties installing HomeBrew, refer to its official documentation.
Step 2: Install Python
Now you can install/update Python with the following command:
Install Python With the Online Installer on Mac
We can also install Python using the Python installer provided on the official site of Python.
Here are the steps you need to follow:
- Go to Python Official Site and download Python with standard macOS .PKG format.
- Then run the downloaded file. Select Continue when you can. You will also have to Agree on the Read Me file.
- The installer will ask where to install Mac, so choose the drive you want.
- After a few easy setups, Python will be installed on your Mac.
Verify Python Installation on Mac
Let's end the Python installation with a simple verification.
To ensure that Python (the version you just installed, let's say 3.7.4) has been set up, run the following command on your terminal.
If you get the version you installed, the installation is verified.
Install Python on Linux
Just like Mac, most Linux distributions like Debian already have Python installed.
To check whether your Linux has Python, run the following command on the terminal.
If it shows the following message:
- "python" not found - Python is not installed
- Python "version-number" - Python is installed
We have two ways of installing Python on Linux:
- Installing Python using the package manager
- Building from source code
After this, we will see how to verify Python installation and how to update the Python version (if you already have Python in your Linux).
Let's get started.
Install Python on Linux Using Package Manager
You can install Python on almost every Linux system using the following command:
Note that this Python command is version-specific. For example, if you want to install Python 2.7, then you need to write:
Once you enter this command, it will ask for your sudo password.
The command also allocates the hard disk space Python needs for installation. Don't worry if the terminal flashes a message to ask where you want to continue with the process.
Type Y (i.e., Yes) and press enter, and the installation begins.
Your terminal will fetch and install many packages for you. You will just have to wait for some time until the process ends.
If it ends without any error message, the installation is complete.
Build From Source Code
This method requires multiple commands and dependencies installed on your computer.
So before starting, make sure you install git, gcc, and make if you don't have them already.
You need to follow three steps to Build Python from Source Code.
- Get the source code
1. Get the Source Code
The Python source code from Python's official GitHub repository is:
Now let's clone it using the following command.
Navigate to the directory where we cloned the Python source code with
Now to configure, run
The configuration begins once you hit enter.
If the process ends without any error, the configuration is done.
This is the final step. To build the files, run
This will put the built files in the location specified by configure's –prefix.
Verify Python Installation on Linux
To verify, simply run the command
or the version you installed.
If the output is
Python installation is verified.
Update Python Version on Linux
If you already have Python installed, you can update it to any version you want.
Suppose you want Python 3.10.7. To update, run:
sudo apt-get update sudo apt-get install python3.10.7
Frequency Asked Questions
1. Do I need to install PIP for Python?
PIP (Pip Install Package) is a Python package manager. When you install Python, pip is installed along with it.
You can check whether pip is installed on your computer using pip command in the terminal.
If pip is not installed, you can install it with this command:
2. How to install Python on Ubuntu?
The easy way of installing Python on Ubuntu is by running the following command on the terminal:
3. Which version of Python should I install?
Unless the company you work for tells you to work in a specific version, you can simply go with the latest version of Python.
4. How to check if Python installation is successful?
To check if Python is successfully installed, run the following command:
If the output of these commands gives you the Python version, it has been successfully installed.
For example, if you installed Python 3.10, the output will be:
Subscribe to Programiz PRO Blog!
Be the first to receive the latest tutorial from Programiz by signing up to our email subscription. Also more bonus like inside looks on the latest feature and many more.