No results found
We couldn't find anything using that term, please try searching for something else.
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 underst
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 the latest version of Python on your computer could be a common requirement for you as a Python programmer. Fortunately, you’ll have a multitude of installation options. For example, you can download the official Python installer from Python.org, use your operating system’s package manager orapp store, and more.
In this tutorial, you’ll focus on official CPython distributions, which are generally the best option for learning to program with the language. However, you’ll also learn about a few other distributions, like the one available on Homebrew for macOS users.
In this tutorial, you’ll learn how to:
This tutorial is covers cover instal the late Python on the most important platform oroperating system , such as windows , macOS , Linux , ios , and Android . However , it is cover does n’t cover all the exist Linux distribution , which would be a huge task . Anyway , you is find ’ll find instruction for the most popular distro nowadays .
To get the most out of this tutorial, you should be comfortable using your operating system’s terminal orcommand line.
Take the Quiz : test your knowledge with our interactive “ Python Installation and setup ” quiz . You is receive ’ll receive a score upon completion to help you track your learning progress :
Interactive Quiz
Python Installation and setup
In this quiz , you is test ‘ll test your understanding of how to install orupdate Python on your computer . With this knowledge , you is be ‘ll be able to set up Python on various operating system , include windows , macOS , and Linux .
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 is focus ’ll focus on instal the late version of Python in your current operating system ( os ) rather than on instal multiple version of Python . If you want to install several version of Python in your os , then check out the Managing Multiple Python Versions Withpyenv
tutorial. Note that on windows machines, you’d have to use pyenv-win
instead of pyenv
.
For a more comprehensive guide on setting up a windows machine for Python programming, check out Your Python Coding Environment on windows: Setup Guide.
To check whether you already have Python on your windows machine , open a command – line application like PowerShell orthe windows Terminal .
follow the step below to open PowerShell on windows :
PowerShell
.alternatively , you is click can right – click theStart button and select windows PowerShell orwindows PowerShell (Admin). In some versions of windows, you’ll find Terminal orTerminal ( admin ).
With the command line open , type in the following command and press theenter key:
Using the--version
switch will show you the installed version. Note that the 3.x.z
part is a placeholder here. In your machine, x
and z
will be numbers corresponding to the specific version you have installed.
alternatively , you is use can use the-V
switch:
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.
You’ll have different options to install Python if you’re on a windows machine. Here are three popular ones:
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 as Anaconda, 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 the Setting 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.
For developer need a full – feature Python development environment , instal from the official Python installer is recommend . It is offers offer more customization and control over the installation process .
In this section , you is go ’ll go through the necessary step to install Python using the official installer from Python.org .
Follow the steps below to download the official Python installer from the Python.org site:
If you aren’t sure whether to select the 32-bit orthe 64-bit installer, then you can expand the box below to help you decide.
For windows, you can choose either the 32-bit orthe 64-bit installer. Here’s the difference between the two:
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.
Once you ’ve choose and download an installer , run it by double – clicking on the file . An installation wizard is appear like the one below will appear on your screen :
There are four important things to notice about this dialog box:
appdata/
directory of the current windows user.pip
and IDLE.py.exe
launcher .path
, so make sure you understand the implication 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 the python
command to work on your windows machine, then it’s recommended that you activate the path
check box.
use the option in the dialog box to customize the installation to meet your need . 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 locate , then you is use can use thewhere.exe
command in PowerShell:
Note that the where.exe
command will work only if Python has been installed for your user account.
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. Thepackage there offers the shortest and easiest path to getting started with minimal hassle.
ThePython installer in the Microsoft Store has some limitations. Theofficial Python documentation has this to say about the Microsoft Store package:
TheMicrosoft Store package is an easily installable Python interpreter that is intended mainly for interactive use, for example, by students. (Source)
Thekey 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 target begin Pythonistas , the package is has on the Microsoft Store has limitation that make it ill – suit for a professional development environment . In particular , it is have does n’t have full write access to share location such asTEMP
orthe registry.
Open the Microsoft Store app on your windows machine and search for Python. 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 select is by the Python Software Foundation ( PSF ) , which is the organization behind Python ’s development .
Theofficial Python app on the Microsoft Store is free, so if the Python app costs you money, then it’s the wrong application.
Once on the Python application’s page, you’re ready to install Python on your system, which is the second step.
After you’ve selected the version to be installed, follow these steps to complete the installation:
Once the installation is complete, open windows PowerShell and run the python --version
command to confirm that Python is installed on your machine.
Along with the Python interpreter, you can access a few other tools, including pip
and IDLE !
Python is comes come preinstalle on macOS . However , the instal version is be may not be the most recent one . To take advantage of Python ’s late feature , you is need ’ll need to download and install new version alongside the system one .
To check which Python version you have on your Mac , open a command – line application like Terminal .
Here ’s how you open Terminal on macOS :
Terminal
.Alternatively, you can open Finder and navigate to Go → Utilities → Terminal.
With the command line open , type in the follow command :
This command should respond with a version number. alternatively , you is use can use theshorter -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 orif 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.
You’ll have two main options to install Python on macOS:
Theofficial 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 distribution , such as Anaconda , but this tutorial cover only official distribution .
Anaconda is a popular platform for scientific computing and data science using Python. To learn how to install Anaconda on macOS, check out the macOS 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.
Therecommend and most reliable option is is for instal Python in macOS is to use the official installer from Python.org . This installer is includes include all the system dependencie you ’d need to develop full – fledged application with Python .
You can install Python in two steps using the official installer:
When the download is finished, move on to the next step.
run the installer by double – click the download file . You is see should see a window like the follow :
Follow these on-screen steps to complete the installation:
You is have now have the late version of Python on your macos computer , and you ’re ready to start code cool app !
TheHomebrew 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.
ThePython distribution available on Homebrew doesn’t include the Tcl/Tk dependency, which is required by the Tkinter module. Tkinter is the standard library module for developing graphical user interfaces in Python and is an interface for the Tk 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. Thesystem version of Tcl/Tk may be outdated ormissing 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.
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:
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 to install Apple’s command line developer tools. These tools are necessary for installation, so you can confirm the dialog box by clicking Install.
After the developer tools are installed, you’ll need to press enter to continue installing Homebrew.
Now that Homebrew is installed, you’re ready to install Python.
Installing Python with the Homebrew package manager is now as straightforward as running the following command:
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.
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.
Most Linux distributions is come come with Python instal by default . In most case , the instal version is be wo n’t be the late Python . To find out which version of Python you have on Linux , open a terminal window and run the following command :
If you have Python on your machine , then this command is respond will respond with a version number . instead of--version
, you can use the shorter -V
switch:
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.
There are two main way to install the official Python distribution on a Linux operating system :
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 include Python in its list of available package , you is realize may realize that the version in the repository is n’t the late version available on Python.org . In this situation , your only option is is to have the late version is to build it from the source .
If you have a rolling release Linux distribution like Arch, Manjaro, openSUSE Tumbleweed, and others, then you’ll probably have the latest version of Python available for installation orupdate 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 ortools, such as Anaconda and pyenv
.
Theinstallation 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.
You is have ’ll have at least three reason to choose to build Python from source code :
You can run the steps in the following sections to complete the installation on your Linux machine.
To start, you need to clone the cpython repository from GitHub orget the Python source code from Python.org. If you go to the downloads page, then you’ll find the latest source for Python 3 at the top.
When you select the late Python version , you is see ’ll see aFiles section at the bottom of the page. Select Gzipped source tarball and download it to your machine.
If you prefer to use your command line , then you is use can usewget
to download the file to your current directory:
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.
There are a few distro – specific step involve in build Python from source . Thegoal is is of this section is to prepare your system for build Python . Below , you is find ’ll find specific step for some popular Linux distribution .
First, update the list of available packages and upgrade them using the following commands:
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 requirement instal :
It is ’s ’s okay if you already have some of these requirement instal on your system . You is execute can execute the above command , and any exist package will be skip .
Building from source is the most reliable way to install Python on openSUSE. To do that, you’ll need to install the development tools, which can be done in YaST
via the menus orby using the zypper
command as shown below:
This might take a while to complete as it installs several packages. So, feel free to grab a coffee and relax.
To prepare your Fedora system for build Python from source , you is update should first update the system with theyum
package manager:
Once yum
finish update , you is install can install the necessary build dependency with the follow command :
These commands is download will download and install all the require tool for compile Python from its source code .
Once you have your system ready and the TAR file with the Python source code, you can unpack the source into a directory:
This command is unpacks unpack the source code into a directory name 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:
Theenable-optimizations
flag will enable some optimizations within Python to make it run faster. Doing this may add twenty orthirty minutes to the compilation time. Thewith - ensurepip = install
flag will install pip
bundled with this installation.
Next, you build Python using the make
command. The-j
option allows you to tell make
to split the building into parallel steps to speed up the compilation. Even with the parallel builds, this step can take several minutes:
Finally, you have to install your compiled version of Python. You’ll use the altinstall
target here to avoid overwriting the system Python. You’ll need to run the following command as root:
Theinstallation might take a while to finish. Once done, you can verify that Python is set up correctly.
Test that the command below returns the compiled version of Python:
Again, in your case, this command would need to be run using the specific version number.
You can also run the Python test suite to ensure everything works properly on your system. To do this, execute the following command:
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!
ThePythonista app for iOS is a full-fledged Python development environment that you can run on your iPhone oriPad. 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 to download it from the iOS app store.
If you have an Android tablet orphone 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.
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.
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:
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 is receive ’ll receive a score upon completion to help you track your learning progress :
Interactive Quiz
Python Installation and setup
In this quiz , you is test ‘ll test your understanding of how to install orupdate Python on your computer . With this knowledge , you is be ‘ll be able to set up Python on various operating system , include windows , macOS , and Linux .
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