Python Installation
Before you can start coding in Python, you need to install it on your computer. Python is available for all major operating systems and can be installed in several ways: - **Official Python Installer**: Recommended for most users from [python.org/downloads](https://www.python.org/downloads) - **Package Managers**: Homebrew (macOS), apt/yum (Linux), Chocolatey (Windows) - **Anaconda Distribution**: Bundles Python with many scientific libraries - **Windows Store**: Official Python package available through Microsoft Store
Installation Guide
Follow one of these methods depending on your platform: - **Windows**: Use the installer from python.org (check 'Add Python to PATH' during installation) - **macOS**: Use Homebrew (`brew install python`) or the official installer. Some macOS versions ship with an older Python, so install Python 3 separately. - **Linux**: Use your package manager (`sudo apt install python3` or `yum install python3`). Run `python3` instead of `python` if needed. - **All Platforms**: Use Miniconda if you want environment management without the full Anaconda distribution.
Verifying Your Installation
After installation, check if Python is installed correctly by running the version command in your terminal or command prompt.
python --version
# or
python3 --version
Python 3.10.6
Choosing a Code Editor
You can write Python in any text editor, but specialized tools make development easier: - **VS Code**: Lightweight and extensible with Python support - **PyCharm**: Full-featured Python IDE (Community edition is free) - **Jupyter Notebook**: Interactive coding environment, great for data analysis - **Sublime Text**: Lightweight editor with Python plugins - **Vim/Emacs**: Popular terminal-based editors for advanced users
Your First Python Program
To confirm your setup, write the classic 'Hello, World!' program: 1. Create a file named `hello.py` 2. Add the code below 3. Run it from your terminal with `python hello.py` (or `python3 hello.py`)
# This is a comment
print("Hello, World!")
Hello, World!
Python Package Management
Python uses `pip` (package installer for Python) to install and manage external libraries.
# Install a package
pip install package-name
# List installed packages
pip list
# Upgrade pip itself
python -m pip install --upgrade pip
Virtual Environments
Virtual environments isolate dependencies per project. This prevents conflicts between packages required by different projects.
# Create a virtual environment
python -m venv myenv
# Activate it (Windows)
myenv\Scripts\activate
# Activate it (macOS/Linux)
source myenv/bin/activate
# Deactivate when done
deactivate
Next Steps
With Python set up, you can: - Learn basic syntax (variables, loops, functions) - Explore the standard library - Install packages like `requests` or `numpy` - Practice using virtual environments - Engage with Python communities for support You're now ready to begin your Python journey! The following lessons will cover core programming concepts.