PCAP Modules and Packages Practice Question
A developer is working on a project that requires the use of a third-party package hosted on a private repository. The developer wants to ensure that the package can be imported without specifying the full repository URL each time. Which approach should be taken?
⚠ Common exam trap
Python Institute often tests the distinction between runtime import path manipulation (like `sys.path`) and package installation configuration, trapping candidates who confuse adding a directory to `sys.path` with configuring a remote package index for pip.
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
✓
Configure the repository URL in pip's configuration file or in requirements.txt.
Configuring the repository URL in pip's configuration file (e.g., `pip.conf`, `pip.ini`, or `~/.config/pip/pip.conf`) or in `requirements.txt` using the `--index-url` or `--extra-index-url` option allows pip to resolve the package from the private repository automatically. This approach ensures that the package can be installed and imported without manually specifying the full URL each time, as pip will use the configured index to locate and download the package.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Append the repository path to sys.path in the script.
Why it's wrong here
Appending a repository URL to sys.path is incorrect because sys.path is a list of local filesystem directory paths, not remote endpoint locators; Python's import machinery will attempt to treat the URL string as a directory path on disk and fail. Even if the repository were checked out locally and its raw path were appended, this would only affect the current interpreter session's module lookup without registering the package with pip or installing its transitive dependencies. It also provides no version metadata or dependency resolution, making the approach non-portable and non-reproducible.
- ✗
Place the package files in the site-packages directory manually.
Why it's wrong here
Manually copying package files into site-packages bypasses pip's dependency resolution, so required third-party libraries will not be installed automatically and version conflicts go undetected. It also leaves no pip metadata (such as RECORD or dist-info), meaning pip cannot cleanly upgrade or uninstall the package, and a future pip command may overwrite or orphan those manually placed files. This approach is especially fragile for packages with compiled extensions or data files that must be placed in multiple locations.
- ✓
Configure the repository URL in pip's configuration file or in requirements.txt.
Why this is correct
This is the standard, reproducible way to make Python's packaging tooling use a private or alternate repository: specify an index URL via index-url or extra-index-url in pip.conf, or use a fully-qualified requirement line (e.g., --extra-index-url) in requirements.txt. During installation, pip queries the configured indexes, resolves the complete dependency graph, and installs the package plus all of its dependencies into site-packages as wheel or sdist distributions. This method respects version constraints, generates proper distribution metadata, and works consistently across environments because the configuration is declarative and versionable.
- ✗
Use os.system to run a pip install command from within the script.
Why it's wrong here
Invoking pip via os.system in a script is an anti-pattern because it shells out to a separate process, captures no meaningful return status through Pythonic exceptions, and requires the script author to manually construct and sanitize command-line arguments. A package installed while the script is running will not be importable in the same interpreter unless the post-installation path is explicitly refreshed, and the operation is invisible to the caller's dependency manager. It also creates coupling to the host operating system's shell, making the script non-portable and harder to debug; instead, dependencies should be installed before the program runs.
Visual reference
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCAP question from scratch — 421 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 →
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.