PCAP Modules and Packages Practice Question
Exhibit
Traceback (most recent call last):
File "script.py", line 1, in <module>
from mypackage import myfunction
ModuleNotFoundError: No module named 'mypackage'A user runs script.py and gets the above error: ModuleNotFoundError: No module named 'mypackage'. Which of the following is the most likely cause?
⚠ Common exam trap
Python Institute often tests the distinction between `ImportError` (module not found) and `AttributeError` (module found but attribute missing), so candidates mistakenly choose Option A when they see an import-related error, confusing a missing module with a missing function within an existing module.
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 package mypackage is not installed or not in the Python path.
The error message 'ModuleNotFoundError: No module named 'mypackage'' indicates that Python cannot find the module 'mypackage'. This typically occurs when the package is not installed or not present in sys.path. Option C directly addresses this cause. The other options are less plausible: Option A would raise an AttributeError, not a ModuleNotFoundError; Option B might cause import issues but would likely result in a circular import error or import error due to naming conflicts; Option D's syntax error would prevent the script from running at all. Therefore, Option C is the most probable cause.
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 function myfunction does not exist in mypackage.
Why it's wrong here
A missing function inside an imported package raises AttributeError at call time (e.g., AttributeError: module 'mypackage' has no attribute 'myfunction'), not ModuleNotFoundError. The import statement itself would succeed because the package file is located and loaded; the name lookup only fails later. The error message shown is about the module mypackage not being found, which is an import-resolution failure, completely unrelated to the existence of a function attribute.
- ✗
The script.py is inside the mypackage directory, causing a conflict.
Why it's wrong here
If script.py were inside the mypackage directory, Python would still locate the mypackage package (as the directory containing script.py would be on sys.path when executing that script), so the import would succeed. A conflict from a local file shadowing a package typically causes an ImportError or a wrong-module pick-up, not a ModuleNotFoundError for the package itself. The traceback explicitly says the module cannot be found, which contradicts the idea that the directory is present and accessible.
- ✓
The package mypackage is not installed or not in the Python path.
Why this is correct
ModuleNotFoundError: No module named 'mypackage' means the import system searched all entries in sys.path and found no module or package named 'mypackage'. This happens when the package is not installed (e.g., not in site-packages), the current working directory is not on sys.path, or the package's parent directory is not listed in the Python path. The fix is to install the package or adjust PYTHONPATH/sys.path so that the import machinery can locate it.
- ✗
There is a syntax error in script.py.
Why it's wrong here
A syntax error would be reported before any import is executed: Python parses the entire script file first, and if a SyntaxError occurs, the traceback would point to the line with the syntax problem, not an import line. The error shown is a runtime import error raised during the import statement's execution, which means script.py was parsed successfully and reached the import line. Syntax errors also produce a SyntaxError exception type, never ModuleNotFoundError, so this option is fundamentally incompatible with the observed error.
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.