Dependency Checker
cyber_modules/dependency_checker.py provides a lightweight bootstrapper that verifies required Python packages are installed before the game starts and automatically installs any that are missing via pip.
This module is intentionally simple and classroom-safe. It only installs the exact packages passed to it by the caller — no hidden package lists or network calls beyond what
pip install performs.ensure_dependencies(packages)
The public entry point. Checks each package by name, installs missing ones, and raises RuntimeError if any installation fails.
An iterable of package/module name strings to verify. In the game this is called with Package names must be importable module names (e.g.
["pygame"]:"pygame", "PIL", "requests"), not PyPI distribution names, since _is_installed uses importlib.import_module.Returns
None if all packages are present or successfully installed. Raises RuntimeError if any installation fails.Behaviour
Filter missing packages
Builds a list of packages for which
_is_installed() returns False. If the list is empty the function returns immediately with no output.Log and install
Prints each missing package name to stdout, then calls
_install_package() for each one._is_installed(module_name)
Attempts to import a module and returns whether it succeeded.
The importable module name to probe, e.g.
"pygame". This must match the name used in import statements, not necessarily the PyPI package name.True if importlib.import_module(module_name) succeeds without raising any exception. False for any exception, including ModuleNotFoundError, ImportError, or errors raised during module initialisation.The broad
except Exception clause is intentional — some partially-installed packages raise non-ImportError exceptions on import (e.g. missing native libraries). Catching all exceptions ensures these cases are treated as “not installed”._install_package(package)
Installs a package using the current Python interpreter’s pip.
PyPI package name to install, e.g.
"pygame". This is passed directly to pip install.True if pip install exits with code 0. False if subprocess.check_call raises any exception (non-zero exit code, binary not found, permission denied, etc.).sys.executable ensures the package is installed into the same Python environment that is running the game, avoiding issues with multiple Python installations or virtual environments.