Learning bite
A Python project you can reproduce
Choose an interpreter, isolate packages, and run a small project from a known directory.
On this page
Give each tool a home
A Python script needs an interpreter to execute its instructions. Python also includes a standard library: modules such as json, pathlib, and unittest that come with the interpreter. Third-party packages are separate downloads. Keeping those packages per project prevents an upgrade for one tool from unexpectedly changing another.
Use Python 3.11 or newer for this module. Install a supported Python through your operating system's documented package manager or the Python download instructions↗. Do not replace the Python installation used by the operating system. On macOS or Linux, open a terminal and check python3 --version before continuing.
Create a fresh directory under your normal practice folder. Run these commands there:
mkdir capacity-tool
cd capacity-tool
python3 -m venv .venv
source .venv/bin/activate
python -c 'import sys; print(sys.executable); print(sys.version.split()[0])'
The first printed path should point inside capacity-tool/.venv. The version should be 3.11 or newer. -m venv asks Python to run its environment-creation module. Activation changes this shell's executable search path; it does not start a server or alter all your terminals. A new terminal needs activation again, or you can call .venv/bin/python explicitly.
Run a file, then import it
Save hello.py in capacity-tool:
def greeting(name: str) -> str:
return f"Hello, {name}"
if __name__ == "__main__":
print(greeting("learner"))
Run python hello.py. Expected output: Hello, learner. Then run python -c 'import hello; print(hello.greeting("operator"))'. Expected output: Hello, operator, without the first greeting. Executing a file gives its __name__ the value "__main__"; importing it gives the module its name. This guard lets tests reuse functions without accidentally running a command-line program.
A module is an importable Python file. A package groups modules. The current working directory affects which relative files your tool opens; it is not automatically the directory containing the script. Keep the terminal at the project root during these exercises.
Keep the project, recreate the environment
Add .venv/, __pycache__/, and *.pyc to this project's .gitignore. Commit your source, tests, and dependency declarations, not the interpreter environment. The next exercises use only the standard library, so there is nothing else to install.
When you later need packages, use python -m pip from the active environment so you know which interpreter receives them. A declared dependency range and a resolved lock file solve different problems: one describes supported versions, while the other records an exact selection. Tools such as uv↗ can manage project metadata, interpreter selection, and a lock file together. That is useful next-step tooling, not a prerequisite for understanding this small program.
Check your understanding
If a new terminal cannot import an installed package, first compare its interpreter path with the one used for installation. Reinstalling globally may hide the actual mismatch. A virtual environment isolates Python packages; it is not a security sandbox and does not isolate the filesystem or network.
Keep this directory for the next lesson. You will replace a greeting with calculations, decisions, and functions. When finished for the day, deactivate leaves the environment without deleting it.
References: Python virtual environments↗, modules↗, and packaging guide↗.
Your notes and evidence
Record observations, questions, or links to your work. Keep credentials out of your notes.
Back up or restore this path
Progress and notes stay in this browser. A backup contains only this learning path.