Installing Python
Installing Python
Section titled “Installing Python”Introduction
Section titled “Introduction”Python runs on all major operating systems. Here’s how to install it on Windows, Linux, and macOS.
Windows Installation
Section titled “Windows Installation”Official Installer (Recommended)
Section titled “Official Installer (Recommended)”- Download from python.org/downloads
- CRITICAL: Check “Add Python to PATH” before clicking Install
- Click “Install Now”
Using winget
Section titled “Using winget”winget install Python.Python.3.12Using pyenv-win (Multiple Versions)
Section titled “Using pyenv-win (Multiple Versions)”pyenv install 3.12.0pyenv global 3.12.0Linux Installation
Section titled “Linux Installation”Ubuntu/Debian
Section titled “Ubuntu/Debian”sudo apt updatesudo apt install python3 python3-pip python3-venvUsing pyenv (Best Practice)
Section titled “Using pyenv (Best Practice)”curl https://pyenv.run | bashpyenv install 3.12.0pyenv global 3.12.0macOS Installation
Section titled “macOS Installation”Using Homebrew (Recommended)
Section titled “Using Homebrew (Recommended)”brew install python@3.12Using pyenv
Section titled “Using pyenv”brew install pyenvpyenv install 3.12.0pyenv global 3.12.0💡 Pro Tip: Always use pyenv when managing multiple Python projects professionally. Never modify the system Python on macOS.
Verifying Installation
Section titled “Verifying Installation”python3 --versionpip3 --versionpython3 -c "print('Hello, Python is working!')"Common Mistakes
Section titled “Common Mistakes”- Forgetting to check “Add Python to PATH” on Windows
- Modifying the system Python on macOS/Linux
- Installing globally instead of using virtual environments
Interview Questions
Section titled “Interview Questions”Q1: What is the difference between python and python3 commands?
A: On Linux/macOS, python may point to Python 2.x (legacy), while python3 explicitly calls Python 3.x.
Q2: What is pyenv and why use it?
A: pyenv manages multiple Python versions on one system, letting you switch between versions per project.
Practice Exercises
Section titled “Practice Exercises”- Install Python and verify using the REPL — calculate the area of a circle with radius 7.
- Create a virtual environment, activate it, install the
requestslibrary, and verify withpip list.