Local Python Tools

getting-started
beginner
Install Python and use VS Code, Jupyter, and the terminal as one local learning toolkit.
  • Level: Beginner
  • Estimated time: 25–40 minutes
  • You will learn: Install Python and use VS Code, Jupyter, and the terminal as one local learning toolkit.
  • Practice in: Google Colab and browser notebooks

Questions

  • What problem does Local Python Tools help us solve in a small Python program?
  • What should we predict before running the example?
  • What value, output, or error should we inspect after changing one line?

Objectives

  • Run a complete example for local Python, editors, terminals, and notebooks in Colab.
  • Explain the example line by line using plain language.
  • Change one part of the code and predict the result before running it.
  • Recognize one common mistake and use the error message as evidence.

Hands-on episode: Local Python Tools

The interpreter runs Python code, the editor helps you write files, the terminal runs commands, and notebooks mix code with explanation. A reliable setup means all four tools are pointing at the same Python environment.

We will learn this by running code, not by memorizing a definition first. Open the Colab notebook from the button above, find this section, and run each cell in order. Keep a small note beside the notebook with three columns: prediction, actual result, and what changed.

Example 1.1

The safest first local check is to ask Python which version is running and where it is installed.

python --version
python -c "import sys; print(sys.executable)"

Run the cell once without editing it. If the result is different from your prediction, leave the prediction visible and write one sentence about the difference. That sentence is more useful than a perfect first guess.

Explain Example 1.1

  • The first command asks the selected Python interpreter to report its version.
  • The second command runs a tiny Python program from the terminal.
  • sys.executable prints the path to the interpreter, which helps you notice when VS Code or Jupyter is using a different Python.

Now explain the example out loud or in a Markdown cell. Use short sentences: “this line creates…”, “this name stores…”, “this output appears because…”. If you cannot explain a line yet, run only the lines above it and inspect the values that exist at that moment.

Challenge 1.1

NoteChallenge

If your system uses python3 instead of python, run the same commands with python3. The important idea is not the exact command name; it is checking that the interpreter you are using is the one you intended.

Show a safe way to approach the challenge
  1. Copy Example 1.1 into a new Colab cell.
  2. Change exactly one value, name, condition, or line.
  3. Write the expected output before running the cell.
  4. Run the cell and compare the actual result with your prediction.
  5. If the result surprises you, undo the change and try a smaller one.

Suggested first move: If your system uses python3 instead of python, run the same commands with python3.

Debugging checkpoint 1.1

WarningDebugging checkpoint

A very common mistake is installing a package with one Python and running code with another. Prefer python -m pip install package_name because it tells the same interpreter that will run your code to install the package.

Do not debug by rewriting the whole example. Read the error type or surprising output, inspect the closest value with print(...) or type(...), then change one thing. This is the same routine you will use in larger projects.

Apply it

Open VS Code, create hello.py, write one print statement, run it from the VS Code terminal, and compare the interpreter path with the one selected in the VS Code status bar.

Finish by adding a Markdown cell that answers: What did this example teach me that I can reuse in a project?

Key points

  • Learn the concept by running a complete, small example first.
  • Predict before execution so your thinking becomes visible.
  • Change one thing at a time so cause and effect stay clear.
  • Treat errors as clues about the exact line or value Python could not handle.

The problem this lesson solves

Colab is a great starting point, but eventually you will want Python on your own computer. Local tools let you save projects in folders, run scripts from files, use an editor, install packages, and work without depending on a browser session.

This lesson introduces four tools as one workflow:

  1. Python interpreter: runs your code.
  2. Terminal: lets you type commands.
  3. VS Code: helps you edit and run project files.
  4. Jupyter: gives notebook-style exploration on your computer.

How local Python tools work together

Local Python work connects files, commands, an interpreter, and output.

flowchart LR
  editor["VS Code<br/>edit hello.py"] --> file["hello.py"]
  terminal["Terminal<br/>python hello.py"] --> interpreter["Python interpreter"]
  file --> interpreter
  interpreter --> output["Output or traceback"]
  interpreter --> packages["Packages via pip"]
  notebook["Jupyter notebook"] --> interpreter

The same interpreter can run a .py script, support VS Code, and power a Jupyter notebook.

1. Install Python and verify it

Installing Python means adding the interpreter to your computer. The safest beginner habit is to verify installation before doing anything else.

Common install paths:

After installation, open a terminal and try these commands:

python --version
python -m pip --version
python -c "print('Python works')"

On some systems the command may be python3 instead of python. On Windows, py may also be available.

Step-by-step explanation

  1. python --version
    • Asks the command named python to report its version.
    • If this works, the terminal can find Python.
  2. python -m pip --version
    • Runs pip, the Python package installer, through the same interpreter.
    • This avoids accidentally using a different pip.
  3. python -c "print('Python works')"
    • Runs a tiny Python program directly from the command line.
    • If it prints Python works, the interpreter can execute code.
WarningCommon mistake

If python is not found, try python3 --version or py --version. If one of those works, use that command consistently in your practice notes.

Check your understanding

2. Terminal basics

A terminal is a place to type commands. You do not need to master every command. For this course, start with a small set.

Command Meaning
pwd show the current folder on macOS/Linux
cd folder_name move into a folder
ls list files on macOS/Linux
dir list files on Windows
python file.py run a Python script

Create a file named hello.py with this code:

print("Hello from a file")

Then run it from the folder that contains the file:

python hello.py

Common mistake: wrong folder

If you see a message like “file not found”, Python may be working in a different folder from the one containing your file. Check your current folder and list the files there.

Check your understanding

3. VS Code as your editor

VS Code is an editor for writing and organizing files. A good beginner setup is:

  1. Open a project folder, not just a single file.
  2. Install the Python extension if VS Code suggests it.
  3. Select the interpreter that matches your terminal command.
  4. Save files before running them.
  5. Use the integrated terminal to run python file.py.

First VS Code script

Create a file named hello.py:

name = "Ada"
print(f"Hello, {name}!")

Run it from VS Code’s terminal:

python hello.py

Why use files?

A .py file is good for code you want to keep, rerun, test, and share. A notebook is good for exploration and explanation. You will use both in this course.

WarningCommon mistake

If VS Code says a package is missing but the terminal can import it, VS Code may be using a different interpreter. Re-select the interpreter and run the check command again.

Check your understanding

4. Jupyter notebooks locally

Jupyter lets you run notebooks on your own computer. A notebook is helpful when you want to mix code, notes, output, and plots.

A common beginner setup is:

python -m pip install notebook
python -m notebook

This installs and starts the classic notebook interface. Some learners prefer JupyterLab; the core idea is the same: code runs in cells, and output appears near the code.

Notebook vs script

Use a notebook when… Use a .py file when…
you are exploring data you want a reusable program
you want notes beside output you want tests and command-line runs
you are learning a concept interactively you are packaging or sharing code

Common mistake: hidden notebook state

Just like Colab, a local notebook remembers values from previously run cells. When confused, restart the kernel and run cells from top to bottom.

Check your understanding

Practice: prove your local setup works

Create a folder named python-practice. Inside it, create hello.py:

name = "Ada"
print(f"Local Python works for {name}!")

Then verify three paths:

  1. Run the file from the terminal.
  2. Open the folder in VS Code and run it again.
  3. Start Jupyter and run the same two lines in a notebook cell.

Key points

TipKey points
  • Local Python lets your computer run scripts outside the browser.
  • Verify with python --version and python -m pip --version.
  • The terminal runs commands; VS Code edits project files; Jupyter runs notebooks.
  • Use python -m pip ... so pip belongs to the interpreter you are using.
  • When tools disagree, check which interpreter each tool selected.

References

  • Python downloads: https://www.python.org/downloads/
  • Python installation docs: https://docs.python.org/3/using/index.html
  • VS Code Python tutorial: https://code.visualstudio.com/docs/python/python-tutorial
  • Jupyter documentation: https://docs.jupyter.org/
Back to top