1

How to install Python: The complete Python programmer’s guide

 2 weeks ago
source link: https://www.pluralsight.com/resources/blog/software-development/python-installation-guide
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The complete Python programmer’s guide

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.

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.

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:

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 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:

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.

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:

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:

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. 

Maaike van Putten

Maaike v.

Maaike is a trainer and software developer. She founded training agency Brightboost in 2014 and spends most of her days and nights working and learning. Training gives her the opportunity to combine her love for software development with her passion to help others boost their careers and be successful. She has trained professionals in the field of Java, Spring, C#, Python, Scrum, React and Angular. A lot of her time is spend staying up-to-date with the latest developments in her field.

More about this author

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK