Appearance
Installing Python
Because Python is cross-platform, it can run on Windows, Mac, and various Linux/Unix systems. Python programs written on Windows can also run on Linux.
To start learning Python programming, you first need to install Python on your computer. After installation, you will have the Python interpreter (which is responsible for running Python programs), a command-line interactive environment, and a simple integrated development environment.
Installing Python 3
Currently, Python has two versions: 2.x and 3.x, which are not compatible with each other. Since the 3.x version is becoming increasingly popular, our tutorial will be based on the latest Python 3.x version. Please ensure that the Python version installed on your computer is the latest 3.x version so that you can smoothly follow this tutorial.
Installing Python on Windows
First, download the Python 3 installer corresponding to your Windows version (64-bit or 32-bit) from the official Python website. Then, run the downloaded .exe
installer:
install-py3
Be sure to check the Add Python 3.x to PATH option, then click Install Now to complete the installation.
Installing Python on Mac
If you are using a Mac, the system comes with Python version 2.7. To install the latest Python 3, there are two methods:
Method 1: Download the Python 3 macOS installer from the official Python website, then double-click to run and install it.
Method 2: If you have Homebrew installed, you can install Python 3 directly by running the command:
bash
brew install python3
Installing Python on Linux
If you are using Linux, I can assume that you have experience managing a Linux system, and installing Python 3 on your own should not be a problem. Otherwise, please switch back to the Windows system.
For many of you who are still using Windows and do not plan to switch to Mac in the short term, you can continue reading the following content.
Running Python
After successful installation, open the Command Prompt window and type python
. There are two possible outcomes:
Scenario 1: Successful Installation
┌────────────────────────────────────────────────────────┐
│Command Prompt - □ x │
├────────────────────────────────────────────────────────┤
│Microsoft Windows [Version 10.0.0] │
│(c) 2015 Microsoft Corporation. All rights reserved. │
│ │
│C:\> python │
│Python 3.12 ... │
│[MSC v... 64 bit (AMD64)] on win32 │
│Type "help", "copyright", "credits" or "license"... │
│>>> _ │
│ │
└────────────────────────────────────────────────────────┘
Seeing an output similar to Python 3.xxx indicates that Python has been installed successfully!
When you see the >>>
prompt, it means you are in the Python interactive environment. You can enter any Python code, and pressing Enter will immediately execute it. Now, type exit()
and press Enter to exit the Python interactive environment (you can also simply close the command line window).
Scenario 2: An Error Occurs
┌────────────────────────────────────────────────────────┐
│Command Prompt - □ x │
├────────────────────────────────────────────────────────┤
│Microsoft Windows [Version 10.0.0] │
│(c) 2015 Microsoft Corporation. All rights reserved. │
│ │
│C:\> python │
│'python' is not recognized as an internal or external co│
│mmand, operable program or batch file. │
│ │
│C:\> _ │
│ │
└────────────────────────────────────────────────────────┘
This is because Windows searches for python.exe
based on the paths set in the Path
environment variable. If it doesn't find it, an error is reported. If you forgot to check Add Python 3.x to PATH during installation, you need to manually add the path where python.exe
is located to the Path
.
If you do not know how to modify environment variables, it is recommended to rerun the Python installer and make sure to check Add Python 3.x to PATH.
Summary
- Learn how to install Python on your computer and become proficient in opening and exiting the Python interactive environment.
- When running Python on Windows, first open the Command Prompt, then run
python
. - When running Python on Mac and Linux, open the Terminal, then run
python3
.