A test can fail because the application is wrong or because it ran with a different interpreter and library set. Make the environment identifiable before using its results. You will create an isolated Python environment, install the course's exact package set, verify a native Collector archive and record the versions actually used. You will not start a receiver in this lesson.
Starting state and effects
Complete the readiness check first. The commands below are for macOS, zsh, native ARM64 and an already installed CPython 3.12. Run as your ordinary user. A maintained Python patch should be provided through your approved installation route before starting; this lesson does not install or modify system Python. Earlier author walkthroughs used 3.12.7. The whole-course author check also executed all runnable lessons on 3.12.15, the security release dated 2026-09-30. That release is source-only; obtain your maintained interpreter through an approved route before this lesson. The author’s isolated source build is not a new learner installation prerequisite or a full host-security audit. Record your actual patch; an old compatibility observation is not a current baseline. Linux, Windows, Intel macOS and a Python process running under translation are outside this verified command path. Use the reading route until a matching walkthrough is checked, rather than selecting a binary by guesswork.
Setup creates ~/ai-eval-practice, a .venv subdirectory, source files, downloaded
tools and an environment record. Internet access is needed for Python package
downloads from PyPI and the official Collector release on GitHub. These are
software downloads; no model or telemetry account is contacted. There is no
cloud resource, model charge or listening port. Have permission to install and
run local software. Do not use sudo or disable certificate/platform protections.
Shell blocks use Bash syntax highlighting; these commands also run in the zsh
shell used here. Run command lines one at a time; stop when a line fails. In the zsh commands,
$HOME means your home directory and quotes keep a path with spaces together.
The fixed directory name is an exercise-owned location, not a placeholder for
an existing project.
python3.12 --version
python3.12 -c 'import platform; print(platform.system(), platform.machine())'
The first command must identify Python 3.12.x. The second must print Darwin arm64 on this route. If either differs, resolve the interpreter/platform first.
Isolate the interpreter
A virtual environment is a directory holding an interpreter entry point and its own installed packages. It is based on an existing Python installation; it does not replace that base installation. Using its explicit interpreter path is enough to select it. Shell activation is convenient but is not required. This follows Python's venv behavior.
For the marker command below, Path(".ai-eval-owned") creates a value
representing that filename. .write_text(...) is its method: an operation
called through the value, which writes the supplied text. The final \n is a
newline. This one-off Python command supplies the marker that the helpers check.
For the first run only:
mkdir "$HOME/ai-eval-practice"
cd "$HOME/ai-eval-practice"
python3.12 -c 'from pathlib import Path; Path(".ai-eval-owned").write_text("ai-eval-practice\n")'
python3.12 -m venv .venv
If mkdir reports that the directory exists, stop and inspect it. Do not create
the marker in an unrelated directory. If it is your earlier course directory,
use the resumption procedure below. -m venv runs Python's environment-creation
module; .venv is its destination. Keep source files outside .venv so the
environment can later be recreated without losing work. The marker identifies
the intended practice directory for the supplied helpers; it is a safety cue,
not an access-control mechanism.
From this point, work in ~/ai-eval-practice:
.venv/bin/python -c 'import sys; print(sys.executable); print(sys.prefix != sys.base_prefix)'
.venv/bin/python -m pip --version
The interpreter path and pip location should be inside this practice directory's
.venv; the Boolean should be True. sys.prefix identifies the environment,
while sys.base_prefix identifies its base Python. python -m pip runs pip
through the named interpreter, avoiding a separate pip command pointing
somewhere else. This selection matters even if your shell prompt looks right.
Install the exact package set
Save this complete file as requirements.txt in the practice directory.
Each == pins one exact release. The file includes dependencies needed by the
direct libraries so a new resolution does not silently choose a different set.
certifi==2026.10.19
charset-normalizer==3.5.2
googleapis-common-protos==1.75.5
idna==3.20
iniconfig==2.3.1
opentelemetry-api==1.45.1
opentelemetry-exporter-http-transport==0.66b1
opentelemetry-exporter-otlp-common==0.66b1
opentelemetry-exporter-otlp-proto-common==1.45.1
opentelemetry-exporter-otlp-proto-http==1.45.1
opentelemetry-proto==1.45.1
opentelemetry-sdk==1.45.1
opentelemetry-semantic-conventions==0.66b1
packaging==26.3
pluggy==1.7.0
protobuf==7.36.2
Pygments==2.21.0
pytest==9.1.1
requests==2.34.2
typing_extensions==4.16.0
urllib3==2.8.0
pytest runs tests. The OpenTelemetry API supplies instrumentation interfaces;
the SDK implements recording; the HTTP exporter sends telemetry using the
OpenTelemetry Protocol (OTLP). You will learn those APIs when you use them.
The remaining packages support those libraries. Some OTel dependencies have
beta-numbered releases, explicitly included in the tested set; top-level 1.x
does not promise stability of every component. Exact version pins support this
exercise's reproducibility, not a security audit or a permanent update policy.
.venv/bin/python -m pip install --disable-pip-version-check -r requirements.txt
.venv/bin/python -m pip check
.venv/bin/python -m pytest --version
-r reads the file, and the first command downloads/installs packages into
.venv. The version-check flag suppresses pip's own update notice; it does not
disable package checks. Expected success includes No broken requirements found. from pip check and pytest 9.1.1. A successful dependency check means
declared package requirements are compatible; it has not tested the application.
Understand a byte hash before trusting a download
Text is characters; bytes are the stored numeric sequence. An encoding such
as UTF-8 maps characters to bytes. A changed space or newline changes a file's
bytes even when a human reads the same policy. SHA-256 calculates a fixed-length
digest from those bytes. Python exposes it through hashlib:
import hashlib
data = b"abc"
print(hashlib.sha256(data).hexdigest())
This complete small program prints
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad.
The b prefix supplies bytes rather than text. sha256(data) creates a hash
object, and .hexdigest() asks that object for its hexadecimal string. An
object groups a value/state with operations; a method is an operation
called through a value, as in object.method(). You do not need to define a
class to use this interface. Python's hash documentation
defines these operations.
Comparing a downloaded archive's digest with the publisher's recorded digest detects an unexpected byte sequence. It does not independently audit the publisher, executable or distribution channel. Hashing personal data would not make it anonymous; later exercises use synthetic inputs instead.
Prepare the Collector without starting it
The course uses the core Collector 0.163.2, darwin_arm64 archive from its
official release.
The expected archive SHA-256 is fixed below. Do not replace the URL with a
latest asset while retaining the old digest. A different architecture needs
a separately checked asset and digest.
Save this complete file as prepare_collector.py in the practice directory:
"""Download and verify the course's native macOS ARM64 Collector; start nothing."""
import hashlib
from pathlib import Path
import platform
import tarfile
import urllib.request
VERSION = "0.163.2"
SHA256 = "56c9c5ab73553f545e3cc4f60373730b8fc262f136e00a6fc13a5ea8107cbe4b"
URL = (
"https://github.com/open-telemetry/opentelemetry-collector-releases/"
"releases/download/v0.163.2/otelcol_0.163.2_darwin_arm64.tar.gz"
)
LICENSE_URL = (
"https://raw.githubusercontent.com/open-telemetry/"
"opentelemetry-collector-releases/v0.163.2/LICENSE"
)
def verify_archive(path, expected):
actual = hashlib.sha256(path.read_bytes()).hexdigest()
if actual != expected:
raise ValueError("Archive SHA-256 mismatch; do not extract or run it")
return actual
def download(url, destination):
response = urllib.request.urlopen(url, timeout=60)
try:
data = response.read()
finally:
response.close()
temporary = destination.with_suffix(destination.suffix + ".part")
temporary.write_bytes(data)
temporary.replace(destination)
def main():
if platform.system() != "Darwin" or platform.machine() != "arm64":
raise RuntimeError("This verified path requires native macOS ARM64 Python")
if Path(".ai-eval-owned").read_text() != "ai-eval-practice\n":
raise RuntimeError("Run from your marked course practice directory")
tools = Path("tools")
tools.mkdir(exist_ok=True)
archive_path = tools / "otelcol_0.163.2_darwin_arm64.tar.gz"
if not archive_path.exists():
download(URL, archive_path)
digest = verify_archive(archive_path, SHA256)
archive = tarfile.open(archive_path, "r:gz")
try:
member = archive.getmember("otelcol")
if not member.isfile():
raise ValueError("Expected a regular otelcol member")
source = archive.extractfile(member)
try:
binary = source.read()
finally:
source.close()
finally:
archive.close()
target = tools / "otelcol"
target.write_bytes(binary)
target.chmod(0o755)
download(LICENSE_URL, tools / "COLLECTOR-LICENSE.txt")
print("Verified Collector archive SHA-256:", digest)
print("Prepared tools/otelcol; no listener started")
if __name__ == "__main__":
main()
Read the code in four parts before running it:
VERSION,URLandSHA256identify the supplied release.verify_archivereads exact bytes and rejects a mismatch before the archive is opened.downloadopens an HTTPS URL with a 60-second timeout for blocking network operations, reads its bytes and closes the response infinally. Afinallyblock runs even when the protected operation raises an exception. It writes a.partfile, then replaces the destination. A failed download is not a verified executable. The timeout is not a whole-download deadline.mainrejects the wrong platform and checks the directory marker.Pathobjects represent filesystem paths;/joins a child path, and methods such asread_bytes,write_bytesandmkdirperform the named file operations. A cached archive is still hashed on every run.- After verification,
tarfile.open(..., "r:gz")reads a gzip-compressed tar archive. The code selects only the regularotelcolmember, reads it, closes the file handles and writes the bytes to the fixed local target. It does not extract arbitrary archive paths.0o755makes that owned binary executable and readable by others, writable by its owner. It also saves the upstream release repository's Apache-2.0 license separately; the archive itself has a README and binary, not a standalone license file.
The if __name__ == "__main__" guard runs main() when this file is executed;
importing it for a later check does not download anything. This is a small
course preparer, not a general-purpose binary installer.
.venv/bin/python prepare_collector.py
tools/otelcol --version
tools/otelcol components
Illustrative success output from the first two commands:
Verified Collector archive SHA-256: 56c9c5ab73553f545e3cc4f60373730b8fc262f136e00a6fc13a5ea8107cbe4b
Prepared tools/otelcol; no listener started
otelcol version 0.163.2
--version and components print information and exit. In the component list,
find receiver otlp and exporter debug: later lessons configure them to
receive and inspect local telemetry. Their presence is readiness evidence;
it is not receipt evidence. Do not start the executable without these
inspection arguments in this lesson.
Record and resume the environment
Save this complete file as record_environment.py:
"""Check this lesson's installed pins and record the actual runtime."""
from importlib.metadata import version
import json
from pathlib import Path
import platform
import subprocess
import sys
def main():
if sys.version_info[:2] != (3, 12) or sys.prefix == sys.base_prefix:
raise RuntimeError("Use this practice directory's CPython 3.12 virtual environment")
if Path(".ai-eval-owned").read_text() != "ai-eval-practice\n":
raise RuntimeError("Run from your marked course practice directory")
packages = {}
for line in Path("requirements.txt").read_text().splitlines():
name, expected = line.split("==")
actual = version(name)
if actual != expected:
raise RuntimeError(f"Version mismatch: {name}: {actual} != {expected}")
packages[name] = actual
binary = str(Path("tools/otelcol").resolve())
collector = subprocess.run([binary, "--version"], check=True,
capture_output=True, text=True).stdout.strip()
if "0.163.2" not in collector:
raise RuntimeError("Unexpected Collector version")
record = {"python": platform.python_version(), "executable": sys.executable,
"platform": platform.platform(), "architecture": platform.machine(),
"packages": packages, "collector": collector,
"adapter_mode": "synthetic-replay", "listener_started": False}
Path("environment-record.json").write_text(json.dumps(record, indent=2) + "\n")
print("Checked", len(packages), "package pins; wrote environment-record.json")
if __name__ == "__main__":
main()
The first guard requires Python 3.12 inside a virtual environment. The loop reads
each name==version pair and asks installed-package metadata for the actual
version. A missing package raises an error; a different version is rejected.
subprocess.run executes the local binary with a list of arguments;
check=True rejects an unsuccessful exit, and capture_output=True, text=True
collects printed output as text. No shell expansion or server is involved.
The JSON record saves actual paths, versions, platform and replay mode.
listener_started: false describes this setup procedure; it is not a scan for
other processes on the machine. Rerunning overwrites only this generated record.
.venv/bin/python record_environment.py
Success prints Checked 21 package pins; wrote environment-record.json. Inspect
that file: interpreter path inside .venv, actual patch recorded, architecture
arm64, 21 expected package values and Collector 0.163.2. Do not publish your
machine paths as evidence to other people without reviewing them.
Close the terminal and open a fresh zsh terminal. The files remain. No activation or remembered shell variable is needed; resume with:
cd "$HOME/ai-eval-practice"
.venv/bin/python -m pip check
.venv/bin/python record_environment.py
Do not repeat the first-run mkdir/marker creation. If installation was
interrupted, run the same requirements installation with this interpreter,
then repeat the checks. If only a download failed, rerun the preparer. A digest
mismatch needs investigation: keep the error, verify the release URL/digest,
then remove only your failed archive and .part file from tools before
retrying the official download. Never bypass verification to get to the next step.
| Symptom | Meaning and safe next check |
|---|---|
python3.12 not found | Required base runtime is missing from that command path; obtain it through an approved route |
pip location outside .venv | Wrong interpreter selected; use the explicit .venv/bin/python -m pip path |
PackageNotFoundError or version mismatch | Install this lock through the same environment interpreter, then repeat pip check and the record |
| Wrong-platform exception or executable-format failure | Compare platform.machine() and selected asset; do not force an ARM64 binary onto another architecture |
| HTTPS trust or permission failure | Check approved network/installation access; keep verification and platform controls enabled |
| Archive digest mismatch | Unexpected bytes; stop before extraction, check origin and retry only the owned failed download |
Keep and clean up deliberately
Keep the marked practice directory, source files, .venv, tools/license/archive
and environment record for subsequent lessons. No process has been started, so
there is no course listener to stop. When abandoning this setup, first inspect
the directory in your file manager, keep your notes/source and remove only your
owned .venv and tools directories plus the generated environment record.
Recreate .venv at its original location if needed; moving it is not a reliable
way to relocate an environment. Do not rerun the preparer while a later lesson's
Collector is running. Stop that owned process first.
Check Your Understanding
Your shell's pip --version points to a global installation, but
.venv/bin/python -m pip --version points inside the practice directory.
record_environment.py passes using the explicit environment interpreter.
Should you reinstall global Python? What evidence supports proceeding, and
what has this lesson still not demonstrated? Also explain why changing only
the Collector URL to an Intel asset is an incomplete repair.
Answer and Reasoning
Hint 1
Which interpreter will execute the course's later commands? Which pip belongs to that interpreter?
Hint 2
Separate package/version readiness from execution of a configured telemetry pipeline. An archive digest belongs to a particular asset's exact bytes.
Explained solution
Proceed using the explicit environment interpreter if the path, package, platform and Collector checks pass. A global pip can belong to a different Python without affecting that invocation. Changing global Python would not improve the evidence and risks unrelated work.
You have verified environment readiness, an archive byte identity and component availability. You have not run application tests, generated fresh inference, started a receiver or established telemetry delivery. Those need later tasks. An Intel asset has different bytes, needs its own digest and a compatible execution path; this course's verified ARM64 route cannot be repaired by a URL substitution alone.
Sources
Version requirements come from the exact publisher releases: pytest 9.1.1, OTel API, SDK and HTTP exporter. See the Collector binary route and release repository license. The helpers use documented path operations, URL access and archive reading.