How to install Python: The complete Python programmer’s guide
An easy guide on how set up your operating system so you can program in Python, and how to update or uninstall it. For Linux, Windows, and macOS.
May 2, 2024 • 12 Minute Read
Whether it’s your first time programming or you’re a seasoned programmer, you’ll have to install or update Python every now and then --- or if necessary, uninstall it. In this article, you'll learn how to do just that.
Some systems come with Python, so to start off, we’ll first check to see if it’s installed on your system before we proceed. To do that, we’ll need to open a terminal. Since you might be new to programming, let’s go over how to open a terminal for Linux, Windows, and macOS.
Table of contents
- Terminals: where and how to run a python script
- How do I set up my system for programming in Python?
- How do I install Python on my operating system?
- What about Python IDEs?
- Running your first script in a terminal
- How do I update Python on my operating system?
- How do I uninstall Python from my operating system?
- Installation complete! Moving on to learning how to program in Python
Terminals: where and how to run a python script
Before we dive into setting up your system so you can program in Python, let’s talk terminal basics and benefits.
What’s a terminal?
As a user, you’re familiar with clicking on your screen to control your computer (this is called using a graphical user interface, or GUI). A terminal, also known as a command line or console, is a different way to control the computer. Instead of clicking, we enter text commands to give the computer instructions.
What are the benefits of using a terminal?
You might wonder why we need a terminal since clicking a mouse seems a lot more convenient than typing commands—especially when you don’t yet know which commands to type. But there are quite a few benefits to using a terminal, including quick access to all available commands and easier task automation.
However, let’s focus on why we need it for working with Python. We use a terminal, or command line, to:
- Install, update, and delete Python on some systems
- Run Python files
- Add Python libraries
- Check the Python version
How does a terminal work?
When you open the terminal, it waits for you to type a command, and then the shell executes it. The shell is a special program that turns the command into actions for the computer’s operating system. You’ll get the result or feedback from the command in the terminal.
Don’t worry about the commands. Once you manage to open the terminal, I’ll tell you which commands to use.
How do I set up my system for programming in Python?
Now let’s dive into the steps you can follow to set up your system to program in Python. First, we’ll open a terminal. Here’s how to open a terminal in Linux, Windows, and macOS.
How to open a terminal in Linux
There are different ways to open a terminal depending on your Linux distributions:
- Press Ctrl + Alt + T
- Access the application menu or launcher, which might be called Activities, Show Applications, or something similar
- Search for Terminal and click the Terminal icon
How to open a terminal in Windows
There are two different built-in options for terminals in Windows. You can open the command prompt or PowerShell:
- Press the Windows button + R, type “cmd” in the Run dialog, and press Enter
- Search for “cmd” or “PowerShell” in the Start bar and press Enter. If you don’t have a search box in the Start bar, click on the Windows icon first and type there.
How to open a terminal in macOS
On macOS, the Terminal app provides access to the Unix part of the OS. Here are two options to open it:
- Use Spotlight search: Press cmd + Space to bring up the Spotlight search box, type “Terminal,” and press Enter.
- Use the Finder window: Navigate to Applications > Utilities and click on Terminal
Check if Python is installed by checking the Python version
Now that we have the terminal open, we can check if Python is installed. In your terminal or command prompt, type the following command:
python --version
Or, for some systems, you might need:
python3 --version
Or for Windows:
py --version
This command will return the version number like the example below if Python is installed.
If Python isn’t installed, you'll see an error message saying Python is unknown or isn't installed, recognized, or added to your system's PATH.
Depending on the outcome, you might be done. If you check the version and it has the version number you want, you’re ready to go.
Let’s make sure you know how to pick the correct Python version.
How to choose the right Python version
Unfortunately, I can’t tell you which version you’ll need. The version depends on what you need to do.
The two major versions of Python are 2 and 3. But versions can look a little different. For example, the latest version at the time of this article is 3.12.3. As you can see, the version number is a lot longer than just the number 3. But since it starts with 3, I'm talking about Python 3.
Let’s start with a very common use case for people installing Python: starting a new project. If you want to start a new project, grab the latest version of Python 3.
But what about Python 2?
Good question. If you’re working on an existing project, the Python versions should be the same. For example, you’ll need version 2 when working on an existing project that uses Python 2. (We typically call Python 2 “legacy.”) Most projects will be Python 3. If you need to work on an existing project that uses a specific version of Python 3, you can use the latest version of Python 3 on your computer.
But—and this is an important but—if you work on an existing project that’s on version 3 but a lower version of Python 3 on the server, it might not support all the newest Python features. To ensure compatibility, choose the specific version of 3 the project is on.
Here’s a good rule of thumb: use the latest version unless you have project requirements that need an older one.
How do I install Python on my operating system?
Now that you know which version you’ll need, let’s install it. Jump to the section that applies to your operating system (Linux, Windows, or macOS).
How to install Python on Linux
Most Linux distributions come with Python pre-installed. If you need to install Python 3, you can use the package manager for your Linux distribution. Here’s what you can use for Ubuntu and other Debian-based systems:
First, type:
sudo apt update
And then type:
sudo apt install python3
How to install Python on Windows
We’ll need to download Python first to install it on Windows. You can get the Python installer from the official Python website. Scroll down to the version you need.
After downloading it, you’ll need to run the installer, which you can find in your Downloads folder.
Make sure to check the box that says “Add python.exe to PATH” to make Python accessible from the command line.
After that, click Install Now and follow the installer prompts to complete the installation.
How to install Python on macOS
Like Linux, your macOS probably has a version of Python because the system comes with Python 2 installed by default. However, it’s likely you’ll need to install Python 3. Here’s the easiest way to do it.
If you’re not using Homebrew yet, let’s install it. (You can thank me later.) Homebrew is a package manager for macOS that allows you to use simple commands in the terminal to install, upgrade, and uninstall all sorts of applications. Fun fact: Being able to write Python is an application in itself.
Here’s how to install Homebrew. Head to the Homebrew website and copy-paste the command into your terminal. This is what the command currently looks like:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once you’ve installed Homebrew, you can easily install Python by running:
brew install python
This command installs Python 3 and Pip3. Pip3 is the Python package installer you’ll need when using Python.
Verify the Python installation
After installing Python, we can check to see if we installed it correctly. Close the terminal you opened and open a new one. Then check the version again by typing in the version-checking command from earlier in this guide.
You should see the Python version number you installed if the installation was successful.
What about Python IDEs?
You can use the most basic text editor, like Notepad on Windows, to write Python code. However, it’s likely you’ll benefit from a slightly fancier application.
An integrated development environment (IDE) is an application that can make your coding experience a lot smoother. It includes features like syntax highlighting, code completion, and built-in debugging and running tools. The three most popular IDEs for Python are:
- PyCharm by JetBrains
- Visual Studio Code (VS Code)
- Jupyter Notebook (commonly used for data analysis)
I use all three but for different purposes. I’ll go for PyCharm when I want to develop applications such as APIs or apps with a GUI. I prefer VS Code when I want to use Python for automation tasks. And Jupyter Notebook is my preferred option for statistical and data purposes.
Running your first script in a terminal
For this example, I’ll use VS code to create a file with a .py extension.
I’ve called my file hello.py and gave it the content:
print("Hello world")
There are different ways to run your code from VS Code. You can see mine shows the play icon (▷) in the right upper corner due to an extension I have called Code Runner. I want to show a more universal way of running this code.
We need to open the folder with the hello.py file in the terminal. There are different ways to do it, but the easiest is to right click in the folder and choose an option such as Open with Terminal.
It looks like this on Windows:
In the terminal that pops up, type “python” or “python3” or “py”—whichever gave you the successful version—followed by the name of the file, including the extension. Press Enter. It should show you the “Hello world” message in the terminal.
This is what the little program did while executing it:
How do I update Python on my operating system?
You’ll want to make sure you’re running the latest version of Python on your system. Here’s how to update Python for Linux, Windows, and macOS.
How to update Python on Linux and macOS
To update Python on Linux and macOS, simply download the latest version from the official Python website and run the installer. It will replace the older version with the newer one.
How to update Python on Windows
To update Python on Windows you download the latest version and run the installer. It will add the version as opposed to replacing it, and you can select which version to choose with the version flag. For example:
py --3.11 --version
or
py --3.11 hello.py
This will run using the specified version of Python. If you don’t specify the version, it will grab the one that’s on the PATH. Which typically is the latest one.
How do I uninstall Python from my operating system?
Now that we know how to update Python on Linux, Windows, and macOS, let’s see how to uninstall it. And of course, the process to uninstall Python varies by operating system.
How to uninstall Python on Linux
Uninstalling Python from a Linux system varies slightly depending on the distribution and how Python was installed. We’re going to use the package manager apt for Debian-based systems.
Note: Many Linux distributions rely on Python for system operations and various software tools. Uninstalling the default system Python could cause system stability issues—and we don’t want that.
First, make sure Python is installed. Go ahead and open a terminal and type:
python3 --version
This command will display the version of Python 3 if it's installed. If it is, we can go ahead and uninstall Python with the apt-get command:
sudo apt-get remove python3
If you have multiple versions installed, and you want to uninstall a specific version, you can replace “python3” with the specific version (e.g., “python3.9”).
You can also remove files and dependencies you don’t need anymore after uninstalling. You can do that by entering the following two commands in the terminal:
sudo apt-get autoremove
sudo apt-get autoclean
These remove packages automatically installed to satisfy dependencies for Python that are no longer needed.
How to uninstall Python on Windows
You have a couple options to uninstall Python on Windows. First, you can uninstall Python via the Add or Remove Programs feature (search for it in the search box).
Search for Python, click on the three dots next to the version you want to uninstall, and choose Uninstall.
Confirm this option in the pop-up box by clicking Uninstall. Python will then start uninstalling. Windows confirms the successful uninstall when it’s done.
And boom, it’s gone!
You can also go to the Control Panel > Programs and select “Uninstall a program.”
It then shows a list of programs you can uninstall. Right click on the one you want and select Uninstall.
No confirmation needed. It’s gone!
How to uninstall Python on macOS
If you’ve installed Python with Homebrew, we can uninstall it that way as well. But before we uninstall Python, it’s good to check which version of Python you installed to ensure we’re removing what we think we’re removing.
Open your terminal and type:
brew list
This command shows you all the packages you’ve installed via Homebrew, including Python. If you have multiple versions, you might see entries like “python@3.9” or just “python.”
To uninstall Python installed using Homebrew, use the brew uninstall command followed by the package name:
brew uninstall python3
If you want to uninstall a specific version of Python, specify it. For example, if I want to remove 3.9, I’d use:
brew uninstall [email protected]
And then it uninstalls it. After uninstalling, you can verify that Python is no longer installed via Homebrew by running:
brew list
This will show you the list of remaining Homebrew packages. Python should no longer appear on the list. Sometimes uninstalling a package leaves behind unused dependencies or temporary files. To clean these up, you can run:
brew cleanup
This command removes any unused files and outdated installations, which helps free up space and keeps your system tidy. If you regret what you just did, you can use Homebrew to install it again with the install command.
Installation complete! Moving on to learning how to program in Python
Now that you’ve successfully installed Python on your system, it’s time to get hands-on and start using your new programming language!
To boost your Python learning journey, Pluralsight has numerous resources available, including online tutorials, courses, and hands-on labs where you get practical experience. The best place to start is Pluralsight's Python 3 learning path, which has beginner, intermediate, and advanced courses, and an online skill test you can use to test your current Python proficiency.