Courseiva
Modules and Packages →mediumMultiple Choice

PCAP Modules and Packages Practice Question

A company has a shared internal library stored in a Git repository. Developers need to use this library in multiple projects without copying the code. Which approach is the most Pythonic and maintainable?

⚠ Common exam trap

Python Institute often tests the misconception that modifying sys.path or using symbolic links is acceptable for sharing code, when in fact the Pythonic and maintainable solution is to package the library and install it via 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

✓

Package the library as a proper Python package and install it via pip in each project's virtual environment.

Packaging the library as a proper Python package and installing it via pip in each project's virtual environment follows the Python packaging standard (PEP 517/518) and the principle of explicit dependency management. This approach ensures versioning, isolation, and easy updates without modifying sys.path or relying on fragile filesystem links, making it the most maintainable and Pythonic solution.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Add the library's directory to sys.path in each project's main script.

    Why it's wrong here

    Adding the library's directory to sys.path in a main script hard-codes a filesystem location into each project, so the code breaks when the repo is cloned elsewhere or when the library moves. It also bypasses Python's packaging metadata system, leaving you with no version declaration, no dependency information, and no clean uninstall or upgrade path. This approach is brittle, non-portable, and not a recognized Python distribution mechanism.

  • ✗

    Create a symbolic link to the library's directory inside each project.

    Why it's wrong here

    Creating a symbolic link inside each project is an OS-level hack that depends on the host filesystem—Windows, for example, often requires developer mode admin privileges—and it is not understood by Python tooling. The link can silently break in CI or on another developer's machine, and it still leaves the library as an untracked directory outside any versioning scheme, so you cannot declare or pin a version. This is neither reproducible nor a standardized Python packaging approach.

  • ✓

    Package the library as a proper Python package and install it via pip in each project's virtual environment.

    Why this is correct

    Packaging the library as a proper Python package and installing it with pip into each project's virtual environment is the industry-standard way to share internal code. The package gets its own version number and can be pinned to a tag or commit in git (for instance, pip install "mylib @ git+https://repo.git@v1.2.3"), with pip resolving its dependencies and installing it into an isolated, per-project site-packages area. This gives you reproducible builds, clean uninstall/upgrade paths, and consistent import behavior across every project.

  • ✗

    Copy the library source code into each project's directory.

    Why it's wrong here

    Copying the library source code into each project directory duplicates the code at every consumption point, so a bug fix in the shared repo must be manually re-copied everywhere. This quickly leads to divergent versions, merge conflicts, and no single source of truth. It is effectively manual vendoring without any tooling to track or sync the copies, making maintenance a nightmare.

About these practice questions

One of 421 original PCAP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.