Courseiva
Modules and PackagesmediumMultiple ChoiceObjective-mapped

PCAP Modules and Packages Practice Question

Your company has two separate Python packages: 'app' and 'lib'. They are maintained by different teams. 'app' depends on 'lib', but 'lib' is still under development and its API changes frequently. To avoid breaking 'app', the team decides to use a virtual environment and install a specific version of 'lib'. However, during development, they need to test 'app' with the latest 'lib' changes from the Git repository. The current workflow is: (1) activate virtual env, (2) install 'lib' from local source using `pip install -e /path/to/lib`. This installs 'lib' as a development package. But one developer reports that after pulling latest 'lib' changes, importing 'lib' in 'app' still uses the old version even after re-running pip install -e. What is the most likely reason?

⚠ Common exam trap

Python Institute often tests the subtle difference between a stale import cache (sys.modules) and a stale install pointer (editable install link), leading candidates to incorrectly choose the caching option when the real issue is a broken or outdated path reference in the development install.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

The editable install may still point to an old copy of the library if the source directory was moved or if there is a stray .egg-link file.

The most likely reason is D. When using `pip install -e` (editable install), pip creates a special `.egg-link` file (or similar pointer) in the site-packages directory that points to the source directory. If the source directory was moved, renamed, or if a stale `.egg-link` file remains from a previous install, pip may still reference the old location, causing the old version to be imported even after re-running the install command. This is a known subtlety of editable installs, especially when the source code is managed under version control and the directory structure changes.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Python caches imported modules in sys.modules, so importing again does not reload the module from disk.

    Why it's wrong here

    The sys.modules cache only affects repeated imports within the same interpreter session; once the Python process exits, the cache is cleared. If the developer is running a fresh script or shell, sys.modules would be empty, so a plain import would re-read the module from disk. However, the real issue is that the re-installed editable package may still resolve to a stale filesystem path, not that the bytecode is cached in memory.

  • The package 'lib' is being imported as a namespace package, so changes are not picked up.

    Why it's wrong here

    A namespace package is created when a directory is imported as a package without an __init__.py file, and it can span multiple directories. In this scenario, there is no evidence that 'lib' lacks an __init__.py or was installed using namespace-package semantics; regular packages use a single, definitive source location. Even if it were a namespace package, changes to a file in the physical source path would still be picked up unless another directory earlier in sys.path shadows it.

  • The .pyc files are not being invalidated because the timestamps are not updated.

    Why it's wrong here

    Python invalidates a .pyc file by comparing the source file's mtime and size; if the source is newer, it recompiles. If timestamps appear 'not updated,' that could cause Python to reuse an old .pyc, but that would only matter if the source being imported were the same file. The real problem is that the import points to the wrong physical copy of the library, so even a forced recompile would compile the obsolete source.

  • The editable install may still point to an old copy of the library if the source directory was moved or if there is a stray .egg-link file.

    Why this is correct

    An editable install for 'lib' registers the source directory via a .pth file or an .egg-link file, which adds that directory to sys.path. If the source directory was moved after the editable install, the recorded path becomes stale; alternatively, a leftover .egg-link from an earlier install can point to the old location. Re-running pip install -e should update this, but if it happened before the move or was interrupted, the import mechanism will still reference the old copy, so changes in the current directory are ignored.

About these practice questions

Courseiva writes every PCAP question from scratch — 169 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.