PCAP Modules and Packages Practice Question
A developer is troubleshooting an ImportError: 'No module named 'config''. The config module is located in a subdirectory 'utils' relative to the script. The script's current working directory is the parent of 'utils'. Which of the following lines, added to the script, will resolve the issue?
⚠ Common exam trap
Python Institute often tests the distinction between modifying sys.path with a directory versus a file path, and the trap here is that candidates mistakenly think appending the full file path (option A) or using os.path.join on a list (option C) will work, when only a directory path appended to the list is correct.
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
✓
sys.path.append('utils')
The ImportError occurs because Python's module search path (sys.path) does not include the 'utils' subdirectory. Adding 'utils' to sys.path via sys.path.append('utils') tells Python to look inside that directory for modules, resolving the import. Option B is correct because it extends the search path to include the directory containing the config module, without altering the script's working directory or incorrectly appending a file 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.
- ✗
sys.path.append('utils/config.py')
Why it's wrong here
sys.path must contain directory paths, not paths to module files. Appending 'utils/config.py' tells the import machinery to treat that exact file as a search location, so when importing config, Python would look under utils/config.py/config.py or fail outright, rather than adding utils/ to the search path. To make config importable, append the containing directory 'utils', not the file itself.
- ✓
sys.path.append('utils')
Why this is correct
This is the correct fix because sys.path is a list of directories Python searches when resolving import statements. Appending 'utils' adds that directory to the end of the list, making any Python module or package inside it visible to the import system. Since the target module lives directly in utils, adding this directory allows 'import config' or a similarly named module to be found.
- ✗
sys.path = os.path.join(sys.path, 'utils')
Why it's wrong here
os.path.join concatenates string path components; sys.path is a list, so calling os.path.join(sys.path, 'utils') raises a TypeError because join does not accept a list as its first argument. Even if the list were coerced to a string, the result would be a single path string, not a list of search directories, and assigning that to sys.path would break the module search mechanism. sys.path must remain a list, so you should append to it directly rather than trying to join.
- ✗
os.chdir('utils')
Why it's wrong here
os.chdir('utils') changes the process's current working directory, which affects relative file I/O but does not modify the module search path stored in sys.path. Imports are resolved against sys.path entries, not against the OS working directory, except for a possible empty-string entry that may be resolved dynamically. Simply changing directories won't make modules in utils importable in a reliable or portable way, so this is not a correct solution.
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.