PCAP Modules and Packages Practice Question
A developer installs a third-party package using pip, but when they try to import it in their script, Python raises a ModuleNotFoundError. The package is definitely installed (pip list shows it). What is the most likely cause?
⚠ Common exam trap
Python Institute often tests the misconception that a package name with a hyphen is invalid for import, leading candidates to choose option B, but the real issue is interpreter mismatch, which is the most common and subtle cause of ModuleNotFoundError in multi-interpreter environments.
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 Python interpreter being used is different from the one where the package was installed.
When a package is installed via pip, it is placed into the site-packages directory of a specific Python interpreter. If the developer runs their script with a different Python interpreter (e.g., one from a virtual environment, a different version, or a system Python vs. a user-installed Python), that interpreter's import system will not search the site-packages where the package was installed, resulting in a ModuleNotFoundError even though pip list shows the package. This is the most common cause of such a mismatch.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
The Python interpreter being used is different from the one where the package was installed.
Why this is correct
Pip installs packages into the site-packages directory of the specific Python interpreter that invoked it, e.g., when using `python -m pip` versus a different interpreter. If the script runs under another interpreter—such as a different virtual environment, a system Python, or an IDE's bundled runtime—that interpreter's `sys.path` won't include the package's location, producing an ImportError. This is the classic environment-mismatch cause.
- ✗
The package name contains a hyphen.
Why it's wrong here
A hyphen in a distribution name is just a packaging convention: pip installs the project as e.g. `my-package`, but the Python import statement must use the underscore form `import my_package`. The package's internal module name is normalized according to PEP 503, so hyphens are converted to underscores for import. Therefore a hyphen alone cannot prevent an installed package from being imported; the error points to an environment issue, not the character in the name.
- ✗
The script is in a directory that shadows the package name.
Why it's wrong here
If the script's own directory contains a file or folder with the exact same name as the third-party package, Python's import system will find that local name first, because the script's directory is placed at the front of `sys.path`. That shadows the installed package, causing either an ImportError or the wrong module being loaded. While possible, this requires a specific local conflict, making it far less likely than an interpreter/site-packages misalignment.
- ✗
The package does not have an __init__.py file.
Why it's wrong here
Modern Python implements implicit namespace packages as described in PEP 420, which means a package does not need an `__init__.py` file to be importable. As long as the directory or module is correctly installed in a location on `sys.path`, Python can recognize it as a namespace package. Thus the absence of `__init__.py` is harmless in normal installation scenarios and does not explain why your script fails to import the package.
Go deeper
Related to this question
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 →
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.