Skip to main content
APPLIED PYTHON / IT AUTOMATION / LESSON 01

Projects, Environments & Dependencies.

Move from scripts that work once to projects someone else can recreate. Identify the interpreter, isolate project dependencies, organize code and verify a real local Python report—without needing production equipment or credentials.

Intermediate foundations75–95 minutes plus optional local projectInteractive local project setup6 real-code challenges
00

What you'll build

Python Fundamentals taught you to write functions and report on fictional IT data. Applied Python is where you turn those functions into a project that can be run again, tested and maintained on your own computer.

  • Organize a small Python project with source, sample data, setup instructions and .gitignore.
  • Identify the active Python interpreter and distinguish environment isolation from a security sandbox.
  • Create and use a virtual environment using the correct command for Windows PowerShell, Windows CMD or macOS/Linux shells.
  • Target pip at the selected Python interpreter and distinguish standard-library from third-party packages.
  • Document direct dependency requirements without confusing pip freeze with a curated project manifest.
  • Separate importable helper functions from the main() entry point.
  • Run and verify a standard-library-only report locally with fictional data, then compare its behavior with browser exercises.
Two connected practice environments: The lesson's local setup guide provides commands to run on your own computer. The JoeLearns code workbench executes Python inside its isolated browser runtime. It does not create real local environments, install pip packages or run your operating-system commands.

Prerequisite: Complete Python Fundamentals or be comfortable with functions, loops, collections, exceptions and JSON. You can review the optional Run Python on Your Computer guide if you haven't run a local script yet.

FROM A SCRIPT TO A PROJECT
01

Know what belongs in a real Python project

A one-file script is a good starting point, but maintaining even a small tool means tracking its source code, setup instructions, dependencies and generated output. Give the project a directory, a clear entry point such as inventory_report.py, and a README describing what the tool does and how to run it. Keep sample input separate from output, and keep secrets out of your source files. That organization lets someone else understand and reproduce your work instead of depending on your computer's history.

Source, instructions, and data

Your .py file is source code. README.md documents setup and usage. samples/inventory.json contains fictional input. Generated reports belong in an output folder when needed, not alongside credentials or system data.

Files that do not belong in Git

A .venv folder is local and recreatable. __pycache__/ and *.pyc are generated caches; .env commonly holds secrets. Exclude them in .gitignore and never commit real passwords or API tokens.

PYTHON / PREDICT AND EXPLAINRead first
from pathlib import Path
project = Path('northstar-report')
print(project.name)
print(project / 'samples' / 'inventory.json')
If you send just inventory_report.py to another learner, what else might they need to run your program reliably? Reveal the explanation after predicting.

They need a supported Python version, any third-party dependencies and instructions for required input files or command arguments. README and a defined project layout make those requirements explicit.

SYNTAX BRIDGE / BEFORE YOU CODE

Terminal commands are not Python statements

A shell runs commands, while the Python interpreter executes Python statements. In the setup explorer, copy one terminal command at a time into PowerShell, Command Prompt or a Unix shell. The commands shown here create only a new training directory.

Terminal / PowerShell, CMD, bash or zshLOCAL TERMINAL · REFERENCE
mkdir northstar-python-tool
cd northstar-python-tool

mkdir creates a folder; cd changes your shell's working directory. The second command affects where the next command runs. These belong in the terminal, not inside a .py file.

Terminal / run a one-line Python checkLOCAL TERMINAL · REFERENCE
python --version
python -c "import sys; print(sys.executable)"
python -m pip --version

--version requests version output; -c runs quoted Python statements without creating a file; -m runs a Python module with the selected interpreter. On Windows, py may be the appropriate launcher; on macOS/Linux, it may be python3.

Predict and explain: Which program interprets `cd northstar-python-tool`: the shell or Python?

The shell. Python reads the code in .py files (or the quoted code passed after python -c), while the shell understands cd and mkdir.

Remember: A project is more than its .py file: record setup, isolate generated artifacts and keep secrets out of source control.
WHICH PYTHON DID YOU RUN?
02

Identify the Python interpreter behind your command

A machine can have more than one Python installation, and a project can have its own virtual environment. The python executable is the interpreter that runs your code; it is not the same thing as your editor. sys.executable shows the interpreter path, sys.version_info reports its version, and sys.prefix versus sys.base_prefix helps identify whether a standard virtual environment is active. Do not judge success solely by a prompt that looks like (.venv); inspect the interpreter actually executing your script.

Interpreter matters

If the script runs with the wrong interpreter, imports may fail even though pip previously installed a package somewhere else. Python -m pip uses the pip module associated with that interpreter.

Version and environment checks

Run python --version, python -m pip --version and a short sys.executable check in your local terminal. sys.prefix differs from sys.base_prefix in a typical venv; the browser Python runtime has a different installation model.

PYTHON / PREDICT AND EXPLAINRead first
import sys
print(sys.version_info.major)
print(sys.version_info.minor)
print(bool(sys.executable))
Why might an import work inside one terminal but fail in another? Reveal the explanation after predicting.

The terminals might resolve python to different interpreters or virtual environments with different installed packages. Confirm the interpreter path and install into the intended environment instead of guessing.

Remember: Always identify which Python runs your program. The interpreter, environment and installed dependencies form a set.
ISOLATION WITHOUT A SECOND COMPUTER
03

Create a project-specific virtual environment

A Python virtual environment keeps a project's third-party packages separate from other projects and from the system installation. From the project folder, use the standard-library venv module to create .venv, then use that environment's interpreter. The environment is a working tool you can recreate, not something to commit to Git. It is not a security sandbox and does not isolate network access, secrets, or operating-system permissions. Creating and activating this environment is a real local-terminal task—not an action the JoeLearns browser editor performs.

Create and use

On Windows, py -m venv .venv is common; on macOS or Linux, python3 -m venv .venv is common. Confirm the command selects the version you intend before creating the environment.

Activation is optional

Activation adjusts your shell's command resolution. You may also run the .venv Python executable by its path without activating. Activation is not an additional security boundary.

PYTHON / PREDICT AND EXPLAINRead first
import sys
# Inspect the interpreter running this code:
is_venv = sys.prefix != sys.base_prefix
print(type(is_venv).__name__)
Why shouldn't you check in .venv alongside your Python source code? Reveal the explanation after predicting.

The environment contains machine-specific executables and installed packages that can be recreated from documented dependencies. Commit source and dependency declarations, then create an environment on each computer.

INTERACTIVE PROJECT SETUP / LOCAL TERMINAL WALKTHROUGH

Build the same project on your computer.

Follow these commands in your own terminal and observe the resulting files. This guide doesn't execute shell commands or install anything. The browser Python coding clinic remains available if you're not ready to set up locally.

STEP 1 / 6 · WINDOWS · POWERSHELL

Start in a dedicated folder

Create a separate workspace for the project. None of the steps below operate on production devices or customer data.

LOCAL TERMINAL — NOT EXECUTED HERE
mkdir northstar-python-tool
cd northstar-python-tool

If activation scripts are restricted on a managed computer, don't weaken policy. Run the .venv Python executable directly or ask your administrator.

PROJECT FILES AT THIS STEP
northstar-python-tool/
Illustration only — check your real files in your local folder.
Step 1 of 6

Use fictional data only. A virtual environment separates dependencies but does not restrict what a Python script can access. Check code and package sources before executing them.

Remember: Use a new .venv per project; recreate it from instructions instead of sharing the directory.
POWERSHELL, CMD AND UNIX SHELLS
04

Activate—or run the exact interpreter

The activation command depends on your operating system and shell. On Windows PowerShell, use .\.venv\Scripts\Activate.ps1; in Windows Command Prompt, use .venv\Scripts\activate.bat. On macOS/Linux with bash or zsh, use source .venv/bin/activate. Once activated, python -m pip installs into the active interpreter. In Windows PowerShell, where.exe python reveals executable lookup; where python by itself is a different PowerShell alias. If a managed device blocks script activation, do not loosen security policy—call the environment's python executable directly or ask the administrator.

PowerShell is not Command Prompt

The .ps1 and .bat activation scripts target different shells. Use the appropriate command rather than copying blindly between terminal types.

Skip activation when convenient

You can run .\.venv\Scripts\python.exe script.py on Windows or .venv/bin/python script.py on macOS/Linux. Direct invocation is useful for repeatable scheduled jobs.

PYTHON / PREDICT AND EXPLAINRead first
from pathlib import PurePosixPath
print(str(PurePosixPath('.venv/bin/python')))
print('Activation is optional')
Do you have to activate a venv before running a Python script with its interpreter? Reveal the explanation after predicting.

No. You can call the interpreter inside the environment directly. Activation only changes how your current shell resolves python and related commands.

Remember: Use the correct shell command; verify the interpreter, and never change system security policy just to activate.
IMPORTS VS INSTALLATIONS
05

Understand the standard library, pip and third-party packages

The Python standard library includes modules such as json, csv, pathlib and argparse. Third-party distribution packages such as requests come from a package index or other trusted source and are installed with pip. A distribution package name may differ from the Python import name, and packages can bring other dependencies. Prefer python -m pip over an unqualified pip command so the installation targets the interpreter you've chosen. Check package provenance and approved versions before installing anything on a managed system.

What comes with Python

import json and import pathlib work with the normal Python standard library; don't run pip install json. Familiar code can still import dependencies already installed by your environment.

What pip actually changes

python -m pip install <package> modifies the chosen interpreter's environment and can access a package index. That command is LOCAL ONLY in this lesson; the JoeLearns browser does not install system packages.

PYTHON / PREDICT AND EXPLAINRead first
import json
import csv
import pathlib
print(json.dumps({'modules': ['json','csv','pathlib']}, sort_keys=True))
Why is python -m pip generally preferable to typing pip without checking anything? Reveal the explanation after predicting.

It invokes the installer associated with the selected Python interpreter, reducing accidental installs into a different environment. You still need to verify the interpreter and trust the packages you install.

SYNTAX BRIDGE / BEFORE YOU CODE

Inspect standard-library modules instead of guessing package names

The first dependency challenge uses sys.stdlib_module_names, which comes from sys rather than from pip. This Python 3.10+ collection contains top-level standard-library module names; it doesn't tell you whether an import will succeed in every environment or whether a third-party package is installed.

Python / module membershipRUNNABLE PYTHON · READ FIRST
import sys

names = sys.stdlib_module_names
print('json' in names)
print('csv' in names)
print('requests' in names)

The in operator checks membership in a set-like collection. json and csv are standard-library modules. requests is a commonly used third-party distribution. Never try `pip install json`.

Predict and explain: Why doesn't seeing `requests` absent from sys.stdlib_module_names prove it is not installed?

The collection categorizes modules supplied with Python; it does not inspect third-party packages installed in your active virtual environment.

Remember: Use standard-library modules without installing them. Review third-party packages and install into the chosen environment.
CAN SOMEBODY RECREATE THIS?
06

Document project dependencies and version expectations

A requirements.txt file can list third-party distribution requirements for a project. For example, requests>=2.32,<3 expresses a compatible version range rather than a single exact version; whether that range is appropriate depends on what your project supports and your security maintenance process. python -m pip install -r requirements.txt installs those dependencies into the chosen environment. pip freeze captures what's currently installed, including transitive packages, but its output isn't automatically a carefully maintained or reproducible lock file. This first project uses standard-library modules, so it has no third-party dependency to install.

Direct requirements versus a snapshot

A curated requirements.txt should state what the project needs. pip freeze captures one environment's installed distributions, often including more than the project directly imports.

Version pins and reproducibility

Exact pins reduce surprises but don't by themselves guarantee byte-for-byte builds or a trusted supply chain. Document Python version compatibility and periodically review dependencies and updates.

PYTHON / PREDICT AND EXPLAINRead first
requirements = '# standard-library-only project\n'
active = [line for line in requirements.splitlines()
          if line.strip() and not line.lstrip().startswith('#')]
print(len(active))
Is a requirements.txt containing only a comment broken? Should you copy all the browser's Python packages into it? Reveal the explanation after predicting.

No. A standard-library-only project may legitimately have no third-party dependencies. Don't copy unrelated packages from the browser or your global Python environment into a project's requirements.

Remember: A requirements file explains external packages; the standard library does not need to be listed as pip dependencies.
SHARE FUNCTIONS WITHOUT DUPLICATION
07

Separate an entry point from reusable helpers

A practical project benefits from small functions that can be imported and tested separately from its command-line entry point. A module can live in another .py file in your project folder. Use import or from ... import to reuse it, and place executable program behavior under if __name__ == '__main__': so importing the module does not accidentally launch a report or modify files. This expands the Files, Exceptions & Modules foundation by focusing on how an actual project stays maintainable.

A helper has one responsibility

Write summarize_hosts(records) to accept Python values and return a report. It should not silently read real customer files or print while being imported.

The entry point owns execution

Put argument reading, deliberate file access and user-facing output in main(). Keep module-level side effects minimal so other code can import and test your functions.

PYTHON / PREDICT AND EXPLAINRead first
def summarize_hosts(hosts):
    return f'{len(hosts)} hosts'

def main():
    print(summarize_hosts(['SW-01', 'AP-02']))

if __name__ == '__main__':
    main()
What changes when this file is imported instead of executed directly? Reveal the explanation after predicting.

Python creates the functions but the guard is false for a normal import, so main() does not run automatically. A caller can import summarize_hosts and pass a different list.

SYNTAX BRIDGE / BEFORE YOU CODE

Read Path.parts and Path.suffix before the file-classification challenge

A file path is made of components. Treating file paths as plain prefixes can misclassify nested .venv or __pycache__ directories.

Python / path componentsRUNNABLE PYTHON · READ FIRST
from pathlib import PurePosixPath

path = PurePosixPath('src/__pycache__/report.pyc')
print(path.parts)
print(path.suffix)
print('__pycache__' in path.parts)

PurePosixPath examines path syntax without reading the filesystem. .parts is a tuple of components and .suffix is the final filename extension. Use pathlib.Path for actual OS file access; PurePosixPath is ideal for predictable practice paths.

Predict and explain: Would `src/.venv/module.py` be generated even though the full string doesn't start with `.venv`?

Yes. The .venv directory is a nested path component, so inspect path.parts instead of checking just the start of the string.

Remember: Keep reusable logic separate from the entry point, and protect executable behavior with the main guard.
PROVE THE LOCAL SETUP WORKS
08

Verify the project and record a repeatable run

A project isn't ready because a package installation printed 'Successfully installed'. Verify the interpreter, run the script, inspect its output, and record the exact steps in your README. For this first project, write a tiny inventory_report.py that reads fictional inventory data using the standard library, prints a deterministic count, and exits without network connections or credentials. Test an empty inventory and a changed one. The browser challenges let you practice its component functions, while the optional local setup guide shows how to run and inspect the real project on your computer.

A successful run has observable evidence

Your script should print expected counts for test data, and errors should be clear. Record the Python command and a sample of expected output in the README.

A clean environment is the real test

A different shell or a freshly created environment should be able to follow the documented setup steps. Don't rely on a package that happened to be installed globally.

PYTHON / PREDICT AND EXPLAINRead first
import json
samples = json.loads('[{"host":"SW-01"},{"host":"AP-02"}]')
print(f'{len(samples)} hosts')
What should you change in the example before declaring your inventory report reusable? Reveal the explanation after predicting.

Test it with an empty list, different fictional hostnames and malformed input. Separate parsing from report logic, document expected input shape, and confirm the same script works when run locally in the intended environment.

Remember: Record how to recreate the environment, then verify actual script output against changed inputs—not just an install message.
YOUR COMPUTER / PROJECT VERIFICATION
09

Prove your local project works

Return to the Project Setup Explorer above and follow its steps with fictional data. Verify that the selected interpreter belongs to your project's .venv and that the sample script prints 2 devices / 1 offline. Then change an input status and verify the report changes. Record the commands you used in README.md.

What you should be able to show

A project folder with source, README.md, .gitignore, requirements.txt and a local .venv, plus a successful run using that environment's Python interpreter. Keep the directory and input sample fictional.

What JoeLearns does not verify

We cannot inspect your computer, verify your package installations or automatically certify that you completed this local task. The path milestone is self-tracked. You can still complete the browser coding exercises without local setup.

Avoid installing third-party packages until they're necessary; the first project uses json from Python's standard library. When later lessons introduce API clients, install only trusted, approved dependencies into the correct environment.

10 / WRITE THE CODE
10

Apply project thinking in real Python

The browser clinic checks interpreter inspection, dependency reasoning, safe project-file classification, reusable entry points and a structured inventory report. Finish the first task below, then complete all six in the coding clinic. Browser code runs without accessing your actual files.

JOELEARNS / PYTHON WORKBENCH

Write it. Run it. Understand it.

Practice real Python helpers for maintainable projects. Create virtual environments and install packages only on your own computer, not in this browser.

Python 3.14 · in-browser
CHALLENGE 01 / 6 · BEGINNER

Inspect the interpreter running your script

Use the provided sys import to create a dictionary named runtime containing Python's major version, the interpreter path as a string and a Boolean flag is_venv (sys.prefix != sys.base_prefix). Print exactly 'Python 3 runtime inspected'. Do not hardcode a specific interpreter path or assume the browser is a local virtual environment.

EXPECTED OUTPUTPython 3 runtime inspected
script.py editableCtrl / Cmd + Enter to run
Your code is stored only in session storage when enabled. Never paste secrets. Clearing this option clears saved drafts, not the editor.
Code executes only when you choose Run or Check. No account needed.
HINTS · OPTIONAL

Try solving it before asking for help. Hints never show a completed program.

PYTHON OUTPUTReady

Your printed output and errors will appear here.

VARIABLE TRACER

Run the code, then step through the executed lines to watch variable values change.

About this environment: The Python runtime is loaded on demand from a version-pinned CDN and runs inside a sandboxed, opaque-origin browser frame. Runs have a time limit. OS/network automation is outside this introductory workbench. If your code calls input(), a response panel appears to supply text to those calls. Don't paste secrets or untrusted scripts.

Next required step: complete the 6-challenge Practice milestone →
NEXT / PRACTICE

Give your code a maintainable home.

Try the independent inventory report after the guided checks. Test with empty records, altered statuses and malformed JSON instead of only matching one output.

Continue to all six project challenges →Next Lesson: Command-Line Tools & Configuration →Applied Python path →
11

Official references

The packaging and interpreter instructions are grounded in maintained Python documentation. Shell command details vary by operating system and installation; verify commands against your own environment.

NEXT REQUIRED STEP · APPLIED PYTHON FOR IT AUTOMATION

Complete the Practice milestone

You've reached the end of this written lesson. Your next step is practice—complete Applied Python Projects Coding Clinic before proceeding to a new lesson. This is milestone 2 of 13. You can revisit the explanation whenever you need it.