Python Environment Setup
Before you start writing Python code, the first step is to install Python on your computer. This chapter will guide you through the installation process on different operating systems.
Check Existing Version
Before installation, you can check if Python is already installed on your system. Open your terminal (Command Prompt or PowerShell on Windows) and type:
python --version
# or
python3 --versionIf the output shows Python 3.x.x, then you already have Python 3 installed. Make sure the version is at least 3.6. If you see "command not found" or the version is 2.x.x, please follow the steps below to install or update.
Installing on Windows
Download the Installer Visit the Python official download page. Click on the latest Python 3 version download link, typically choosing "Windows installer (64-bit)".
Run the Installer After downloading, double-click the
.exefile to launch the installation wizard.Important Configuration On the first screen of the installation wizard, make sure to check
Add Python 3.x to PATH. This adds Python's installation path to your system's environment variables, allowing you to run thepythoncommand from any directory. Then clickInstall Nowto proceed with the default settings.Verify Installation After installation completes, open a new terminal window and type
python --version. If it displays the version number, the installation was successful.
Installing on macOS
macOS usually comes with an older Python 2 version. We recommend using Homebrew, a package manager, to install the latest Python 3.
Install Homebrew (if not already installed) Open Terminal and run:
bash/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Install Python using Homebrew
bashbrew install python3Homebrew will automatically handle paths and dependencies.
Verify Installation After installation, type
python3 --versionin Terminal to verify.
Installing on Linux
Most modern Linux distributions (like Ubuntu, Fedora) come with Python 3 pre-installed. You can install or update it through the package manager.
On Ubuntu/Debian:
sudo apt update
sudo apt install python3On Fedora/CentOS:
sudo dnf install python3
# or
sudo yum install python3Package Manager: Pip
When you install Python 3, pip is usually installed automatically. pip is Python's official package manager, used to install and manage third-party libraries (such as Django, NumPy, etc.).
You can check if pip is installed successfully with:
pip --version
# or
pip3 --versionYour Python development environment is now ready!