This lesson on Installing Python is hands-on and example-driven. You will learn the official, best-practice method for installing Python on a Windows machine. You will be able to verify existing installations, download the correct installer, and make an informed decision about configuring the critical Windows PATH environment variable.
What You'll Be Able To Do
- Verify the current Python installation status using the command line.
- Access and execute commands within the Windows PowerShell terminal.
- Locate and download the official Python installer from the correct source.
- Configure the installer to correctly update the Windows PATH environment variable.
- Recognize the necessity of using isolated virtual environments for future projects.
Detailed Concept Walkthrough
1. Command Line Interface (CLI)
The CLI (like PowerShell) is a text-based interface used to execute system commands and interact with Python directly. It is essential for checking versions and running scripts.
- Mechanism: PowerShell interprets text commands and executes corresponding programs or system functions.
- Under the Hood: When you type a command, the shell searches specific system directories (defined by PATH) for an executable file matching that command.
- Best Practice: Always use PowerShell (or Terminal) for Python interaction on Windows, not the older Command Prompt.
# Open PowerShell via Windows Search
# Check the version of Python currently accessible by the system
python --version
Key Takeaway: The CLI is the primary tool for verifying installation and running Python programs outside of an IDE.
2. The Windows PATH Variable
The PATH is a list of directories the operating system checks when you type a command without specifying the full file location. It allows you to run 'python' from any directory.
- Mechanism: When you type 'python', the OS iterates through every folder listed in the PATH variable until it finds the 'python.exe' executable.
- Under the Hood: If Python is not added to the PATH, the OS cannot find the executable globally, forcing you to navigate to the installation directory to run it.
- Best Practice: Check the "Add Python to PATH" box during installation to enable global access, which simplifies command-line usage significantly.
Key Takeaway: Adding Python to PATH makes the interpreter globally accessible from any terminal window.
3. Verifying Installation Status
Before installing, you must check if Python is already present to avoid version conflicts or unnecessary downloads. This is done using a specific CLI command.
- Mechanism: The
python --versioncommand executes the firstpython.exefound in the PATH and instructs it to report its version number. - Under the Hood: If the command returns a version number (e.g., Python 3.10.5), the installation is successful and globally accessible.
- Nuance: If the command opens the Microsoft Store, it means the system cannot find a local installation on the PATH.
# Execute this command in PowerShell
python --version
# Expected output: Python 3.11.5 (or similar)
Key Takeaway: Always verify the installation status using
python --versionbefore proceeding with a new install.
4. Virtual Environments (Venvs)
Virtual environments are isolated directories containing specific Python versions and package dependencies for a single project. They prevent conflicts between different projects.
- Mechanism: A Venv creates a local copy of the Python interpreter and installs packages only within that isolated folder.
- Under the Hood: When activated, the Venv temporarily modifies the shell's environment variables to point to its local Python and package directories instead of the global installation.
- Best Practice: While the installer sets up the global interpreter, always use a virtual environment for every new data analytics project.
Key Takeaway: Venvs are crucial for project isolation and dependency management, preventing 'dependency hell.'
Topics Covered in Installing Python
- Check Existing Version (0:29 - 1:02) — The learner is instructed to open PowerShell and use
python --versionto verify current installation status. - Download Official Installer (1:29 - 1:55) — The video guides the user to the official python.org website to download the latest Windows installer executable.
- Configure PATH Variable (2:04 - 3:26) — The critical step of checking the "Add Python to PATH" box during the installation process is demonstrated and explained.
- Final Verification (3:26 - 3:33) — The learner verifies the successful installation by running
python --versionagain in a new PowerShell window. - Introduce Virtual Environments (3:33 - 3:56) — The concept of virtual environments is briefly introduced as a necessary best practice for project isolation.
Python Cheat Sheet
-
python --version— Reports the globally accessible Python versionpython --version -
PowerShell— Windows command line interface for system interactionpython script.py -
python.org— Official source for the Python installer -
Add to PATH— Installer option enabling global command line accesspython -
Global Installation— System-wide installation of the Python interpreter
Comparison Table
| Feature | Official Installer (python.org) | Microsoft Store Install |
|---|---|---|
| Source | Python Software Foundation | Microsoft Store |
| Configuration | Full control over PATH | Limited configuration |
| Use Case | Data analytics, development | Quick testing, basic use |
| Access | Global access via PATH | Often restricted/sandboxed |
Common Pitfalls
- Mistake: Installing Python without checking the "Add to PATH" box. Avoid: Rerunning the installer and selecting the PATH option.
- Mistake: Assuming Python is installed if
python --versionfails. Avoid: Checking if the command opens the Microsoft Store instead. - Mistake: Using the global installation for all project dependencies. Avoid: Creating and activating a dedicated virtual environment for each project.
FAQs
- Why is adding Python to the PATH so important?
It allows you to execute the
pythoncommand from any directory in your terminal without typing the full installation path. - Should I use the Microsoft Store version? No, the official installer from python.org provides better control over system configuration and environment variables needed for development.
- What if I already have an old version installed? It is best practice to uninstall the old version first, or ensure the new version is placed higher in the PATH list.
- Does this installation work for Mac or Linux? No, this lesson focuses exclusively on the Windows installation process and its specific PATH configuration.