Movatterモバイル変換


[0]ホーム

URL:


— FREE Email Series —

🐍 Python Tricks 💌

Python Tricks Dictionary Merge

🔒 No spam. Unsubscribe any time.

Browse TopicsGuided Learning Paths
Basics Intermediate Advanced
aialgorithmsapibest-practicescareercommunitydatabasesdata-sciencedata-structuresdata-vizdevopsdjangodockereditorsflaskfront-endgamedevguimachine-learningnewsnumpyprojectspythonstdlibtestingtoolsweb-devweb-scraping

Table of Contents

Recommended Video Course
Python Basics: Setting Up Python

Python 3 Installation & Setup Guide

How to Install Python on Your System: A Guide

byLeodanis Pozo RamosPublication date Jan 19, 2025Reading time estimate 25mbasicsbest-practicestools

Table of Contents

Remove ads

Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding:Python Basics: Setting Up Python

Installing Python on your system involves a few straightforward steps. First, check if Python is already installed by opening a command-line interface and typingpython --version orpython3 --version. You can install Python on Windows using the official installer from Python.org or through the Microsoft Store. On macOS, you can use the official installer or Homebrew. For Linux, use your package manager or build Python from source.

By the end of this tutorial, you’ll understand how to:

  • Check if Python is installed by runningpython --version orpython3 --version in a command-line interface.
  • Upgrade Python by downloading and installing the latest version from Python.org.
  • Install and manage multiple Python versions withpyenv to keep them separate.

This tutorial covers installing the latest Python on the most important platforms or operating systems, such as Windows, macOS, Linux, iOS, and Android. However, it doesn’t cover all the existing Linux distributions, as that would be a massive task. Nevertheless, you’ll find instructions for the most popular distributions available today.

To get the most out of this tutorial, you should be comfortable using your operating system’sterminal or command line.

Free Bonus:Click here to get a Python Cheat Sheet and learn the basics of Python 3, like working with data types, dictionaries, lists, and Python functions.

Take the Quiz: Test your knowledge with our interactive “Python Installation and Setup” quiz. You’ll receive a score upon completion to help you track your learning progress:


Python 3 Installation & Setup Guide

Interactive Quiz

Python Installation and Setup

In this quiz, you'll test your understanding of how to install or update Python on your computer. With this knowledge, you'll be able to set up Python on various operating systems, including Windows, macOS, and Linux.

Windows: How to Check or Get Python

In this section, you’ll learn to check whether Python is installed on your Windows operating system (OS) and which version you have. You’ll also explore three installation options that you can use on Windows.

Note: In this tutorial, you’ll focus on installing the latest version of Python in your current operating system (OS) rather than on installing multiple versions of Python. If you want to install several versions of Python in your OS, then check out theManaging Multiple Python Versions Withpyenv tutorial. Note that on Windows machines, you’d have to usepyenv-win instead ofpyenv.

For a more comprehensive guide on setting up a Windows machine for Python programming, check outYour Python Coding Environment on Windows: Setup Guide.

Checking the Python Version on Windows

To check whether you already have Python on your Windows machine, open a command-line application likePowerShell or theWindows Terminal.

Follow the steps below to open PowerShell on Windows:

  1. Press theWin key.
  2. TypePowerShell.
  3. PressEnter.

Alternatively, you can right-click theStart button and selectWindows PowerShell orWindows PowerShell (Admin). In some versions of Windows, you’ll findTerminal orTerminal (admin).

Note: To learn more about your options for the Windows terminal, check outUsing the Terminal on Windows.

With the command line open, type in the following command and press theEnter key:

Windows PowerShell
PS>python--versionPython 3.x.z

Using the--version switch will show you the installed version. Note that the3.x.z part is a placeholder here. In your machine,x andz will be numbers corresponding to the specific version you have installed.

Alternatively, you can use the-V switch:

Windows PowerShell
PS>python-VPython 3.x.z

Using thepython -V orpython—-version command, you can check whether Python is installed on your system and learn what version you have. If Python isn’t installed on your OS, you’ll get an error message.

Knowing the Python Installation Options on Windows

You’ll have different options to install Python if you’re on a Windows machine. Here are three popular ones:

  1. Theofficial Python installer for Windows: This approach involves downloading the Python installer directly from thePython.org website. It’s recommended for intermediate and advanced developers who need more control during the setup process.
  2. TheMicrosoft Store: The quickest installation option on Windows involves using the Microsoft Store app. This is recommended for beginner Python programmers looking for an easy-to-set-up interactive experience.
  3. TheWindows subsystem for Linux (WSL): The WSL allows you to run a Linux environment directly on Windows.

In this section, you’ll focus on only the first two options, which are the most popular ones on Windows environments.

Note: You can also complete the installation on Windows using alternative distributions, such asAnaconda, but this tutorial covers only official distributions.

Anaconda is a popular platform for scientific computing and data science with Python. To learn how to install Anaconda on Windows, check out theSetting Up Python for Machine Learning on Windows tutorial.

If you want to install Python in the WSL, you can read the Linux-related sections of this tutorial after installing the Linux distribution of your choice.

Windows: How to Install Python Using the Official Installer

For developers needing a full-featured Python development environment, installing from the official Python installer is recommended. It offers more customization and control over the installation process.

In this section, you’ll go through the necessary steps to install Python using the official installer from Python.org.

Step 1: Download the Official Python Installer

Follow the steps below to download the official Python installer from the Python.org site:

  1. Open your browser and navigate to thedownloads page for Windows on Python.org.
  2. Under thePython Releases for Windows heading, click the link for theLatest Python 3 Release - Python 3.x.z.
  3. Scroll to the bottom and select eitherWindows installer (64-bit) orWindows installer (32-bit).

If you aren’t sure whether to select the 32-bit or the 64-bit installer, then you can expand the box below to help you decide.

For Windows, you can choose either the 32-bit or the 64-bit installer. Here’s the difference between the two:

  • If your system has a 32-bit processor, then you should choose the 32-bit installer. If you attempt to install the 64-bit version on a 32-bit processor, then you’ll get an error at the beginning, and the installation will fail.
  • On a 64-bit system, either installer will work for most purposes. The 32-bit version will generally use less memory, but the 64-bit version performs better for applications with intensive computation.

If you’re unsure which version to pick, go with the 64-bit version.

If you have a 64-bit system and would like to switch from 64-bit Python to 32-bit (or vice versa), then you can just uninstall Python and then reinstall it by downloading the other installer.

When you finish downloading the installer, then you can move on to the next step.

Step 2: Run the Python Installer

Once you’ve chosen and downloaded an installer, run it by double-clicking on the file. An installation wizard like the one below will appear on your screen:

Windows Python Installer

There are four important things to notice about this dialog box:

  1. The default install path is in theAppData/ directory of the current Windows user.
  2. TheCustomize installation button allows you to customize the installation location and some additional features, including installingpip andIDLE.
  3. TheUse admin privileges when installing py.exe allows every user on the machine access thepy.exe launcher.
  4. TheAdd python.exe to PATH checkbox is also unchecked by default. There areseveral reasons that you might not want Python onPATH, so make sure you understand the implications before you check this box.

As you can conclude, the official Python installer gives you granular control over the installation process on Windows.

Note: If you want thepython command to work on your Windows machine, then it’s recommended that you activate thePATH check box.

Use the options in the dialog box to customize the installation to meet your needs. Then clickInstall. That’s it! You now have the latest version of Python 3 on your Windows machine!

If you’re interested in where the installation is located, then you can use thewhere.exe command in PowerShell:

Windows PowerShell
PS>where.exepythonC:\Users\realpython\AppData\Local\Microsoft\WindowsApps\python.exe

Note that thewhere.exe command will work only if Python has been installed for your user account.

Windows: How to Install Python From the Microsoft Store

If you’re new to Python and focused primarily on learning the language rather than building professional software, then you can install Python from the Microsoft Store. The package there offers the shortest and easiest path to getting started with minimal hassle.

The Python installer in the Microsoft Store has some limitations. The official Python documentation has this to say about the Microsoft Store package:

The Microsoft Store package is an easily installable Python interpreter that is intended mainly for interactive use, for example, by students. (Source)

The key takeaway is that the Python package on the Microsoft Store is “intended mainly for interactive use.” It’s designed for students and people learning Python for the first time.

In addition to targeting beginning Pythonistas, the package on the Microsoft Store has limitations that make it ill-suited for a professional development environment. In particular, itdoesn’t have full write access to shared locations such asTEMP or the registry.

Step 1: Open the Python App Page on the Microsoft Store

Open the Microsoft Store app on your Windows machine and search forPython. You’ll likely see multiple versions that you can choose to install. Select the latest version of Python available in the store to open the installation page.

Note: Make sure that the Python application you’ve selected is by thePython Software Foundation (PSF), which is the organization behind Python’s development.

The official Python app on the Microsoft Store is free, so if the Python app costs you money, then it’s thewrong application.

Once on the Python application’s page, you’re ready to install Python on your system, which is the second step.

Step 2: Install the Python App

After you’ve selected the version to be installed, follow these steps to complete the installation:

  1. Click theGet button.
  2. Wait for the app to download and install.

Once the installation is complete, open Windows PowerShell and run thepython --version command to confirm that Python is installed on your machine.

Along with the Python interpreter, you can access a few other tools, includingpip andIDLE!

macOS: How to Check or Get Python

Python comes preinstalled on macOS. However, the installed version may not be the most recent one. To take advantage of Python’s latest features, you’ll need to download and install newer versions alongside the system one.

Checking the Python Version on a macOS

To check which Python version you have on your Mac, open a command-line application likeTerminal.

Here’s how you open Terminal on macOS:

  1. Press theCmd+Space keys.
  2. TypeTerminal.
  3. PressEnter.

Alternatively, you can open Finder and navigate toGo → Utilities → Terminal.

With the command line open, type in the following commands:

Shell
$python3--version

This command should respond with a version number. Alternatively, you can use the shorter-V switch, which has the same effect.

In practice, you’d want to get the latest version of Python if none of the above commands returns a version number or if you have a version of Python 3 that isn’t the latest available. Now, you can read through the following sections to learn about the different options for installing Python on macOS.

Knowing the Python Installation Options on macOS

You’ll have two main options to install Python on macOS:

  1. Theofficial Python installer for macOS: This option involves downloading the official installer from the Python.org website and running it on your machine.
  2. TheHomebrew package manager: This option involves downloading and installing the Homebrew package manager if you don’t already have it and then running the required installation command in your terminal application.

The official Python installer and the Homebrew Python distribution will work, but the Python Software Foundation maintains only the official installer.

Note: You can also complete the installation on macOS using alternative Python distributions, such asAnaconda, but this tutorial covers only official distributions.

Anaconda is a popular platform for scientific computing and data science using Python. To learn how to install Anaconda on macOS, check out themacOS installation guide from the official Anaconda documentation.

Now that you know your option for installing Python on macOS, it’s time to get your hands dirty and go through the installation process.

macOS: How to Install Python Using the Official Installer

The recommended and most reliable option for installing Python in macOS is to use the official installer from Python.org. This installer includes all the system dependencies you’d need to develop full-fledged applications with Python.

Step 1: Download the Python Official Installer

You can install Python in two steps using the official installer:

  1. Open a browser window and navigate to thedownloads page for macOS.
  2. Under thePython Releases for macOS heading, click the link for theLatest Python 3 Release - Python 3.x.z.
  3. Scroll to the bottom and clickmacOS 64-bit universal2 installer to start the download.

When the download is finished, move on to the next step.

Step 2: Run the Python Installer

Run the installer by double-clicking the downloaded file. You should see a window like the following:

macOS Python Installer

Follow these on-screen steps to complete the installation:

  1. PressContinue a couple of times until you’re asked to agree to the software license agreement. Then clickAgree.
  2. Select the install destination. You most likely won’t need to change the default location, so go ahead and clickInstall to start the installation.
  3. When the installer is finished copying files, double-click theInstall Certificates command in the finder window to ensure your SSL root certificates are updated.

You now have the latest version of Python on your macOS computer, and you’re ready to start coding cool apps!

macOS: How to Install Python From Homebrew

The Homebrew package manager is another good option for installing Python on macOS. You can install Python using the Homebrew package manager in two steps, but first, you need to be aware of some limitations of the Python package on Homebrew.

The Python distribution available on Homebrewdoesn’t include the Tcl/Tk dependency, which is required by the Tkinter module. Tkinter is the standard library module for developinggraphical user interfaces in Python and is an interface for theTk GUI toolkit, which isn’t part of Python.

Homebrew doesn’t install the Tk GUI toolkit dependency. Instead, it relies on an existing version installed on your system. The system version of Tcl/Tk may be outdated or missing entirely and could prevent you from using Tkinter.

Finally, note that the Python distribution on Homebrew isn’t maintained by the Python Software Foundation and could change at anytime.

Step 1: Install the Homebrew Package Manager

If you already have Homebrew installed on your macOS system, then you can skip this step. If you don’t have it installed, then use the following procedure:

  1. Open a browser and navigate tohttp://brew.sh/.
  2. Copy the installation command under theInstall Homebrew heading.
  3. Open a terminal window and paste the command, then pressEnter.
  4. Enter your macOS user password when prompted.

Depending on your Internet connection speed, the process may take a few minutes to download all of Homebrew’s required files. Once the installation is complete, you’ll be back at the shell prompt in your terminal window.

Note: If you’re doing this on a fresh install of macOS, you may get a pop-up alert asking you toinstall Apple’s command line developer tools. These tools are necessary for installation, so you can confirm the dialog box by clickingInstall.

After the developer tools are installed, you’ll need to pressEnter to continue installing Homebrew.

Now that Homebrew is installed, you’re ready to install Python.

Step 2: Install Python With Homebrew

Installing Python with the Homebrew package manager is now as straightforward as running the following command:

Shell
$brewinstallpython

This command will download, install, and set up the latest version of Python on your machine. You can make sure everything went correctly by testing if you can access Python from the terminal. If you get an error message, then go through the install steps again to make sure you have a working installation.

Linux: How to Check or Get Python

In this section, you’ll learn how to check which version of Python, if any, is on your Linux computer. You’ll also learn about the installation options to get the latest Python on Linux systems.

Checking the Python Version on Linux

Most Linux distributions come with Python installed by default. In most cases, the installed version won’t be the latest Python. To find out which version of Python you have on Linux, open aterminal window and run the following command:

Shell
$python3--version

If you have Python on your machine, then this command will respond with a version number. Instead of--version, you can use the shorter-V switch:

Shell
$python3-V

Either of these switches will give you the version number of the Python installation that the command is associated with. If your current version is outdated, you’ll want to get the latest version of Python.

Knowing the Python Installation Options on Linux

There are two main ways to install the official Python distribution on a Linux operating system:

  1. Install from a package manager: This is the most common installation option on most Linux distributions. It involves running a command from the command line.
  2. Build from source code: This option can be difficult because it involves running a series of commands from the command line as well as making sure you have the correct dependencies installed to build Python from its source code.

Not every Linux distribution has Python in their package repository. So, depending on your distribution, building Python from source code might be your only option.

Note: Because of the wide variety of Linux distributions out there, you won’t find an official installer that you can execute on your Linux system to install Python like you can on macOS and Windows.

If your Linux distribution includes Python in its list of available packages, you may realize that the version in the repository isn’t the latest version available on Python.org. In this situation, your only option to have the latest version is to build it from the source.

If you have arolling release Linux distribution likeArch,Manjaro,openSUSE Tumbleweed, and others, then you’ll probably have the latest version of Python available for installation or update using the system’s package manager. In this situation, to update your Python, you’d only have to update the system with the appropriate commands.

Note: You can also complete the Python installation on Linux using alternative distributions or tools, such asAnaconda andpyenv.

The installation option boils down to whether your Linux has Python available in its software repository and whether you need to control the details of the installation.

Linux: How to Build Python From Source Code

You’ll have at least three reasons to choose to build Python from source code:

  1. You need to install the latest version of Python or a version unavailable on your distribution’s repository.
  2. You need to control how Python is compiled, such as when you want to lower the memory footprint on embedded systems.
  3. You want to try outpre-release versions to explore new features.

You can run the steps in the following sections to complete the installation on your Linux machine.

Step 1: Download the Python Source Code

To start, you need to clone thecpython repository fromGitHub or get the Python source code from Python.org. If you go to thedownloads page, then you’ll find the latest source for Python 3 at the top.

When you select the latest Python version, you’ll see aFiles section at the bottom of the page. SelectGzipped source tarball and download it to your machine.

If you prefer to use your command line, then you can usewget to download the file to your current directory:

Shell
$wgethttps://www.python.org/ftp/python/3.x.z/Python-3.x.z.tgz

For this command to work, you must specify the version to download. When the tarball finishes downloading, there are a few things you’ll need to do to prepare your system for building Python.

Step 2: Prepare Your System for Building Python

There are a few distro-specific steps involved in building Python from source. The goal of this section is to prepare your system for building Python. Below, you’ll find specific steps for some popular Linux distributions.

Ubuntu, Debian, and Linux Mint

First, update the list of available packages and upgrade them using the following commands:

Shell
$sudoaptupdate$sudoaptupgrade

Note that because you’re using thesudo command, you’ll be prompted to provide your root password.

Next, make sure you have all of the build requirements installed:

Shell
$sudoaptinstall-ymakebuild-essentiallibssl-devzlib1g-dev\libbz2-devlibreadline-devlibsqlite3-devwgetcurlllvm\libncurses5-devlibncursesw5-devxz-utilstk-dev

It’s okay if you already have some of these requirements installed on your system. You can execute the above commands, and any existing packages will be skipped.

openSUSE Linux

Building from source is the most reliable way to install Python onopenSUSE. To do that, you’ll need to install the development tools, which can be done inYaST via the menus or by using thezypper command as shown below:

Shell
$sudozypperinstall-tpatterndevel_C_C

This might take a while to complete as it installs several packages. So, feel free to grab a coffee and relax.

Fedora Linux

To prepare your Fedora system for building Python from sources, you should first update the system with theyum package manager:

Shell
$sudoyum-yupdate

Onceyum finishes updating, you can install the necessary build dependencies with the following commands:

Shell
$sudoyum-ygroupinstall"Development Tools"$sudoyum-yinstallgccopenssl-develbzip2-devellibffi-devel

These commands will download and install all the required tools for compiling Python from its source code.

Step 3: Build and Install Python on Your System

Once you have your system ready and the TAR file with the Python source code, you can unpack the source into a directory:

Shell
$tarxvfPython-3.x.z.tgz$cdPython-3.x.z/

This command unpacks the source code into a directory named after the TAR file. Note that the TAR file will show a specific Python version rather than3.x.z in your output.

Now you need to run the./configure script to prepare the build:

Shell
$./configure--enable-optimizations--with-ensurepip=install

Theenable-optimizations flag will enable some optimizations within Python to make it run faster. Doing this may add twenty or thirty minutes to the compilation time. Thewith-ensurepip=install flag will installpip bundled with this installation.

Next, you build Python using themake command. The-j option allows you to tellmake to split the building into parallel steps to speed up the compilation. Even with the parallel builds, this step can take several minutes:

Shell
$make-j8

Finally, you have to install your compiled version of Python. You’ll use thealtinstall target here to avoid overwriting the system Python. You’ll need to run the following command as root:

Shell
$sudomakealtinstall

The installation might take a while to finish. Once done, you can verify that Python is set up correctly.

Step 4: Verify Your Python Installation

Test that the command below returns the compiled version of Python:

Shell
$python3.x--versionPython 3.x.z

Again, in your case, this command would need to be run using the specific version number.

You can also run the Pythontest suite to ensure everything works properly on your system. To do this, execute the following command:

Shell
$python3.x-mtest

You’ll probably want to find something else to do for a while, as your computer will be running tests for some time. If all the tests pass, then you can be confident that your brand-new Python build will work as expected!

iOS: How to Install Python

ThePythonista app for iOS is a full-fledged Python development environment that you can run on your iPhone or iPad. It features a Python editor, technical documentation, and an interpreter, all rolled into a single app.

Pythonista is surprisingly fun to use. It’s a great little tool when you’re stuck without a laptop and want to work on your Python skills on the go. It comes with the complete Python standard library and includes full documentation you can browse offline.

To set up Pythonista, you need todownload it from the iOS app store.

Android: How to Install Python on Android

If you have an Android tablet or phone and want to practice Python on the go, then you have several options available.

For example,Pydroid 3 features an interpreter that you can use for REPL sessions. It also allows you to edit, save, and execute Python code. It has a free version and also a paid Premium version that supports code prediction and code analysis.

Online: How to Use a Python Playground

If you want to try out Python without installing it on your machine, then you’ll find several websites offering an online Python interpreter and some related functionalities. Here’s a quick list of these tools:

These online Python interpreters may not be able to execute complex code, but they should be adequate for basic code examples, which could be a nice way to get started.

Conclusion

You now know how to install the latest version of Python on your operating system. Your Python programming journey is just beginning.

In this tutorial, you’ve learned how to:

  • Check whichversion of Python is installed on your system
  • Install the latest version of Python onWindows,macOS, andLinux
  • Use Python onmobile devices like phones or tablets
  • Use Python on the Web withonline interpreters

You’re now ready to get started programming in Python!

Take the Quiz: Test your knowledge with our interactive “Python Installation and Setup” quiz. You’ll receive a score upon completion to help you track your learning progress:


Python 3 Installation & Setup Guide

Interactive Quiz

Python Installation and Setup

In this quiz, you'll test your understanding of how to install or update Python on your computer. With this knowledge, you'll be able to set up Python on various operating systems, including Windows, macOS, and Linux.

Frequently Asked Questions

Now that you have some experience with installing Python on your system, you can use the questions and answers below to check your understanding and recap what you’ve learned.

These FAQs are related to the most important concepts you’ve covered in this tutorial. Click theShow/Hide toggle beside each question to reveal the answer.

You can check if Python is installed by opening your terminal or command prompt and typingpython --version orpython3 --version. If Python is installed, you’ll see a version number.

On Windows, you can use the official Python installer or the Microsoft Store. On macOS, you can use the official installer or Homebrew. On Linux, you can install Python from your package manager or build it from source.

To upgrade Python, download the latest version from Python.org and install it over your existing version, or use your system’s package manager to update Python to the latest version available.

Yes, you can install multiple versions of Python on the same machine by using tools likepyenv on macOS and Linux, orpyenv-win on Windows, to manage different versions.

You can manage Python environments and versions using tools likevenv for creating virtual environments andpyenv for managing multiple Python versions on your system.

Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding:Python Basics: Setting Up Python

🐍 Python Tricks 💌

Get a short & sweetPython Trick delivered to your inbox every couple of days. No spam ever. Unsubscribe any time. Curated by the Real Python team.

Python Tricks Dictionary Merge

AboutLeodanis Pozo Ramos

Leodanis is a self-taught Python developer, educator, and technical writer with over 10 years of experience.

» More about Leodanis

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

MasterReal-World Python Skills With Unlimited Access to Real Python

Locked learning resources

Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert Pythonistas:

Level Up Your Python Skills »

MasterReal-World Python Skills
With Unlimited Access to Real Python

Locked learning resources

Join us and get access to thousands of tutorials, hands-on video courses, and a community of expert Pythonistas:

Level Up Your Python Skills »

What Do You Think?

Rate this article:

What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment below and let us know.

Commenting Tips: The most useful comments are those written with the goal of learning from or helping out other students.Get tips for asking good questions andget answers to common questions in our support portal.


Looking for a real-time conversation? Visit theReal Python Community Chat or join the next“Office Hours” Live Q&A Session. Happy Pythoning!

Keep Learning

Related Topics:basicsbest-practicestools

Recommended Video Course:Python Basics: Setting Up Python

Related Tutorials:

Keep reading Real Python by creating a free account or signing in:

Already have an account?Sign-In

Almost there! Complete this form and click the button below to gain instant access:

Python Logo

Get the Python Cheat Sheet (Free PDF)

🔒 No spam. We take your privacy seriously.


[8]ページ先頭

©2009-2025 Movatter.jp