PCAP Modules and Packages Practice Question
A Python script fails with 'ModuleNotFoundError: No module named 'myapp.config''. The environment variable PYTHONPATH is not set. Which of the following is the most likely cause?
⚠ Common exam trap
Python Institute often tests the distinction between a module not being found (ModuleNotFoundError) versus a package structure issue (missing __init__.py) or a code error (SyntaxError), tempting candidates to pick the more specific but incorrect cause.
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 module is located in a directory not included in sys.path
When PYTHONPATH is not set, Python relies solely on sys.path to locate modules. sys.path includes the script's directory, standard library paths, and site-packages. If 'myapp.config' is not in any of these directories, Python raises ModuleNotFoundError. Option A correctly identifies that the module is in a directory not included in sys.path.
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 module is located in a directory not included in sys.path
Why this is correct
The import system resolves module names by scanning every directory listed in sys.path, which normally includes the script's own directory, entries from PYTHONPATH, and the interpreter's site-packages. If the module's parent directory is not represented anywhere in that list, Python cannot locate the file regardless of how clearly the module is named, and the import statement terminates with ModuleNotFoundError. This is the most direct and common cause of this exception, and the fix is to add the directory to sys.path, modify PYTHONPATH, or install the module properly.
- ✗
The module's __init__.py is missing
Why it's wrong here
Missing __init__.py does not, by itself, trigger ModuleNotFoundError in modern Python. Since Python 3.3, PEP 420 allows namespace packages, so a directory without __init__.py can still be imported as a package as long as its parent is on sys.path; if a regular module file is missing from that directory, the error would reference the submodule, not a package-level failure. In practice, a missing __init__.py might cause a different symptom, such as the package not being recognized as a regular package, but it would not produce the exact exception shown in the scenario.
- ✗
The module is installed in a different Python version's site-packages
Why it's wrong here
Multiple Python interpreters on a system each maintain their own site-packages directory, so a package installed via pip for one interpreter is not automatically visible to another. When the current interpreter imports a module, it only searches its own sys.path, which includes that interpreter's site-packages but not another version's. This situation can indeed cause ModuleNotFoundError, but it is essentially a specialized case of the module's directory being absent from sys.path; the more fundamental issue in the question is that the target directory was never added to the search path.
- ✗
The module has a syntax error
Why it's wrong here
A syntax error in a module would never surface as ModuleNotFoundError, because the error occurs during the compilation of the module's source code after the file has already been located and loaded. The import system first resolves the module path by scanning sys.path; if the file is found, it then compiles the code, and any syntax problem raises SyntaxError with a specific filename and line number. The distinction is important: ModuleNotFoundError signals a search-path failure, not an execution or compilation failure within an already-imported module.
Go deeper
Related to this question
About these practice questions
One of 169 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 →
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.