pip install -r requirements.txt: Install, Create and Fix Errors

pip install from requirements txt: Command Prompt installing packages into a virtual environment

Running pip install from a requirements txt file takes one command: activate your virtual environment in the project folder, then run pip install -r requirements.txt. pip reads every line and installs those packages and versions: Every command here really ran on Python 3.12.5 in Windows Command Prompt, installing two small packages from PyPI into a … Read more >>

How to Make a Directory in Python (os and pathlib)

Make a directory in Python: Command Prompt output of pathlib mkdir creating nested folders

Need to make a directory in Python? Use os.mkdir(“name”) for a single folder, or Path(“a/b/c”).mkdir(parents=True, exist_ok=True) to create nested folders without errors if they already exist: Each folder in these examples was created for real by Python 3.12.5 on Windows, and the screenshots show the Command Prompt output. I’ll cover os.mkdir(), os.makedirs(), pathlib, dated and … Read more >>

Types of Errors in Python (With Real Examples)

Types of errors in Python: Command Prompt output of common built-in exceptions and their messages

There are three main types of errors in Python: syntax errors, which stop the code from running at all; runtime errors (exceptions), which crash it partway through; and logical errors, which run fine but give the wrong answer. All the error messages below are copied from Python 3.12.5 running in a Windows Command Prompt, so … Read more >>

How to Install Python on Ubuntu Linux (2026 Guide)

Install Python on Linux Ubuntu: packages.ubuntu.com listing the python3 version for each Ubuntu release

Most Ubuntu Linux systems already include Python 3, so installing Python on Ubuntu often just means adding pip and venv. Open a terminal and run: Which version you get depends on your Ubuntu release. I checked packages.ubuntu.com in October 2026, and the screenshots are real captures of that page and the deadsnakes PPA. This guide … Read more >>

Web Scraping with Python: A Step-by-Step Tutorial

Scraping web data with Python: a Requests and Beautiful Soup crawler saving books to CSV

Scraping web data with Python comes down to two steps: download the page with requests, then pull out the parts you need with Beautiful Soup. Here’s the whole idea in four lines: Together we’ll build a small scraper for books.toscrape.com, a fake bookstore made for practice, on Python 3.12.5, requests 2.34.2 and beautifulsoup4 4.15.0. The … Read more >>

How to Copy a List in Python (5 Ways + Deep Copy)

Copy a list in Python: Command Prompt output comparing a shallow copy and deepcopy of a nested list

Want to copy a list in Python? Call new = old.copy(), or use the slice old[:]. Both give you a separate list, so changing one won’t touch the other. For lists that contain other lists, use copy.deepcopy(): Screenshots come straight from Python 3.12.5 in Command Prompt, with the output text pasted under each code block. … Read more >>

How to Install Python on Mac (macOS) in 2026

Install Python on Mac: the python.org macOS downloads page with the latest Python 3 release

You can install Python on Mac OS X (now macOS) in a few minutes: download the macOS installer from python.org, run it, then type python3 –version in Terminal. Homebrew users can do it in one command instead: As of October 2026, python.org lists Python 3.14.8 as the latest release, and Homebrew’s python@3.14 formula is on … Read more >>

Best Python Libraries for Web Scraping (With Examples)

Python libraries for web scraping: Requests and Beautiful Soup scraping quotes in Command Prompt

The best Python libraries for web scraping are Requests and Beautiful Soup for simple pages, lxml for speed, Scrapy for large crawls, and Selenium or Playwright for sites that build their content with JavaScript. Most projects start with the first two: My examples scrape quotes.toscrape.com and books.toscrape.com, two sandbox sites built for practice, using Python … Read more >>

Python with open() as file: Read, Write and Append Safely

Python with open as file: Command Prompt output showing the file closed after the with block

with open(“file.txt”) as file: is how Python opens a file safely. The with block gives you the file object as file, and Python closes it automatically when the block ends, even if an error happens inside: You’ll see real output from Python 3.12.5 on Windows 11 in every Command Prompt screenshot below. I’ll cover reading … Read more >>

Principal Component Analysis (PCA) in Python with scikit-learn

Principal component analysis in Python: scikit-learn PCA reducing the wine dataset to two components

Principal component analysis in Python takes three lines with scikit-learn: scale your features, create PCA(n_components=2), and call fit_transform(). You get a smaller set of new columns that keep most of the information: I tested this on Python 3.12.5 with scikit-learn 1.9.1, using the wine and iris datasets that ship with scikit-learn, so you won’t need … Read more >>