AlgoMaster Logo

Setting Up Environment

Low Priority20 min readUpdated June 7, 2026
Listen to this chapter
Unlock Audio

Before you can run a single line of Python, your machine needs a working Python install, a way to install third-party packages, and an editor that understands the language. By the end of this lesson, python --version will print a real version string in your terminal, you'll have pip ready to install packages, and an editor open and waiting.

This chapter only covers setup.

The Setup Flow

The whole process is short. Install Python for your operating system, verify it works, learn the pip basics, pick an editor, and run something.

If you've installed compilers or runtimes for other languages before, none of this will surprise you. Take the steps in order and don't skip the verification one. A lot of "Python isn't working" stories turn out to be a terminal that was opened before the installer finished updating PATH.

Installing Python

The Python you want is Python 3.12 or 3.13 (or whatever the latest stable 3.x release is when you're reading this). Avoid Python 2; it was retired in 2020 and isn't supported anymore. Avoid the very newest release candidate too, because some third-party libraries take a few weeks to catch up to fresh majors.

macOS

macOS ships with a Python, but it's there for the operating system, not for you. Don't build projects on top of it. Install a fresh copy instead.

Option 1: the official installer. Visit , click the macOS download for the latest 3.x release, and run the .pkg file. The installer drops python3 into /usr/local/bin (or /opt/homebrew/bin on Apple Silicon for Homebrew-managed paths) and updates your PATH so a new terminal can find it.

Option 2: Homebrew. If you already use Homebrew, this is a one-liner:

That installs the current stable Python plus pip. After it finishes, open a fresh terminal and run:

The exact patch number (the .0 part) depends on when you install.

Windows

On Windows, head to , download the latest 3.x installer for Windows (pick Windows installer (64-bit) unless you're on an ARM machine), and run it.

When the installer opens, there's one checkbox that matters more than every other option combined:

Check that box before clicking Install. If you don't, the python command won't work in PowerShell or Command Prompt, and you'll waste an hour trying to figure out why. Also check Install pip if it isn't already ticked.

After the installer finishes, close any open PowerShell windows and open a fresh one. Environment variables set by an installer aren't picked up by terminals that were already running. Then verify:

Windows also ships a small tool called the `py` launcher. It comes with the official installer and is the recommended way to run Python on Windows when you have multiple versions installed:

The first command runs the latest Python it can find. The second pins to a specific version. If python isn't on your PATH for some reason, py usually still works, which makes it a handy fallback.

Linux

Most Linux distributions ship a Python 3, but it may be older than what you want. The system Python also has a quiet job: package managers and parts of the distro itself depend on it. Don't install random packages into the system Python, because you can break tools that ship with your distro.

The right move is to install a recent Python through your package manager, then do project work inside virtual environments (more on those in a bit).

Debian or Ubuntu:

The python3-venv package matters. Without it, you can't create virtual environments, which you'll want very soon.

Fedora, RHEL, or CentOS Stream:

After installing, verify:

If your distro's repos are stuck on an older Python (Ubuntu LTS releases sometimes lag a release or two behind), you have two options: live with the older version for now, or use a version manager like pyenv to install a newer Python alongside the system one.

Verifying the Install

A few short commands tell you whether everything is wired up correctly.

If that prints command not found, try:

On macOS and most Linux distros, the binary is called python3, not python. We'll talk about why in a moment. For now, whichever one prints a 3.x version is the one you'll use.

Also check pip, the package installer:

The (python 3.13) part at the end is what you care about. It tells you which Python this pip will install packages into. If pip says it's tied to Python 3.13 but python --version says 3.12, you have two installs and your PATH order is mixing them.

If pip isn't found, try pip3 --version or python -m pip --version. The -m pip form runs whichever pip is bundled with the currently active Python, which is the most reliable way to invoke it.

python vs python3: Why Both?

For about a decade, Python had two parallel major versions: Python 2 (released 2000) and Python 3 (released 2008). They were not source-compatible. To keep old scripts from breaking, the convention emerged that python referred to Python 2 and python3 referred to Python 3. Many Linux distros still follow that rule, which is why on Ubuntu the command is python3 and python either doesn't exist or points at Python 2.

Python 2 was officially retired in January 2020. On modern Windows, the official installer maps python to Python 3 directly. On macOS with Homebrew, you get python3 as the primary binary; python may or may not be set depending on your install. The portable rule:

  • Type python3 if you want to be safe everywhere.
  • Type python if your system has it pointed at Python 3 (Windows usually does; some macOS and Linux setups do too).

You can always check with python --version. If it prints a 3.x number, the short name works. If it prints 2.x or says "not found", stick to python3.

Working with pip

pip is Python's package installer. It pulls libraries from the Python Package Index (PyPI), the central registry where the community publishes open-source code. The first time you need to make an HTTP request, parse a CSV, or chart a dataset, you'll reach for a third-party library, and pip is how you get it.

The handful of commands you'll use constantly:

That installs the requests library (a popular HTTP client) plus its own dependencies. To see what's installed:

To see details about one specific package:

To remove a package:

To freeze the current set of installed packages and their versions into a file (the conventional name is requirements.txt):

The output file lists every installed package pinned to an exact version. Someone else can then reproduce your environment by running pip install -r requirements.txt.

Choosing an Editor

A plain text editor plus python is enough to write and run code. But an editor with Python support pays for itself within the first hour. It catches typos as you write, autocompletes function names, jumps you to definitions, and runs your code with a keypress.

Two editors dominate Python work. Here's how they compare:

CriteriaVS Code + Python extensionPyCharm Community
CostFreeFree (Community); Pro is paid
Best forGeneral use, polyglot devs, beginnersPure Python work, larger projects
StrengthsLightweight, huge extension ecosystem, great if you already use it for other languagesDeep Python tooling, smart refactoring, built-in debugger and test runner
WeaknessesPython support is good but needs an extension; settings can feel scatteredHeavier, uses more memory, can feel cluttered until you learn the layout
Recommended for this course?Yes, especially if you're newYes, especially for bigger Python-only projects

If you don't already have a preference, install VS Code with the official Python extension from Microsoft. It's free, fast to set up, and the same editor works for the other languages you'll likely touch.

VS Code Setup

Download VS Code from . Install and launch it. Click the Extensions icon on the left sidebar (or press Cmd+Shift+X / Ctrl+Shift+X), search for Python, and install the one published by Microsoft. That single extension pulls in language support, debugging, and integration with the Python interpreter you installed earlier.

To make sure VS Code is using the right Python, open the Command Palette (Cmd+Shift+P on macOS, Ctrl+Shift+P elsewhere) and run Python: Select Interpreter. The list shows every Python it found on your machine. Pick the 3.x install you just verified.

PyCharm Community Setup

Download it from . Make sure to grab Community Edition, which is free. The paid Professional edition adds support for web frameworks, databases, and remote development, but a beginner doesn't need any of that.

On first launch, PyCharm asks if you want to create a new project. Click New Project. PyCharm wants to know which Python to use; the dropdown should auto-detect the one you installed. If it doesn't, click the gear icon and point it at the path that python --version runs (find it with which python3 on macOS/Linux or where python on Windows).

PyCharm creates a project folder and, by default, a virtual environment inside it. You don't need to understand that fully yet; it's the same python -m venv idea you'll see in a moment, just wired up for you.

Running Python Code

There are three ways to actually run Python, and you'll use all of them at different times.

1. The REPL (interactive shell). Type python (or python3) with no arguments:

The >>> prompt is the REPL, which stands for Read-Eval-Print Loop. You type one expression, hit Enter, and Python prints the result. Try it:

exit() (or Ctrl+D on macOS/Linux, Ctrl+Z then Enter on Windows) leaves the REPL. The REPL is perfect for trying out a one-liner, checking what a function returns, or remembering how a method works.

2. Running a `.py` file. Save a file called cart.py with this content:

Then run it from the same directory:

This is how you'll run almost every program you write.

3. One-liners with `-c`. Sometimes you want to run a single expression without opening the REPL or creating a file:

Handy in shell scripts and CI pipelines, or just to check something quickly.

Virtual Environments (Preview)

There's one more piece you should know exists, even though we'll only sketch it here. A virtual environment is an isolated copy of Python and its installed packages, attached to a single project. Instead of installing requests globally, you create a virtual environment for your project and install requests into that. Two projects on the same machine can then depend on different versions of the same library without colliding.

Python ships with a tool called venv for this. Inside a project folder:

That creates a folder called .venv containing its own Python and an empty package list. To start using it, you activate it. The exact command depends on your shell:

Once activated, your shell prompt usually shows the venv name in parentheses, and any pip install you run goes into this venv, not into the system Python. To leave, run deactivate.

That's enough to know for now.

Other Tools (uv, pyenv): Brief Mention

The Python tooling space has moved fast in the last few years, and two newer tools come up a lot:

  • `uv` is a fast Python package installer and project manager written in Rust. It can install packages 10 to 100 times faster than pip and is increasingly the default in modern Python projects. For now, sticking with pip is fine.
  • `pyenv` is a Python version manager. It lets you install multiple Python versions side by side and switch between them per-project. Useful if your distro's Python is too old, or if you maintain projects pinned to different Python versions.

Mentioning them here so the names aren't a mystery the first time you see them in a tutorial or job description.