Courseiva
Modules and Packages →hardMultiple Select

PCAP Modules and Packages Practice Question

Which THREE factors can cause an 'ImportError' when trying to import a module?

⚠ Common exam trap

Python Institute often tests the distinction between ImportError and other exceptions like SyntaxError or ModuleNotFoundError, and the trap here is that candidates may incorrectly think a syntax error in a module causes an ImportError, when in fact it raises a SyntaxError at import time.

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 a C extension that fails to load.

If a module is a C extension (e.g., a .so or .pyd file) and it fails to load due to missing dependencies, incompatible architecture, or a linking error, Python raises an ImportError. This is distinct from a syntax error in Python source code, which would raise a SyntaxError, not an ImportError.

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 file has a syntax error.

    Why it's wrong here

    A syntax error in the module's source code is discovered by the parser during bytecode compilation, before the module is ever executed. When the import system attempts to compile the file, the parser raises a SyntaxError (or a subclass like IndentationError), not an ImportError. This is a compile-time failure distinct from the import machinery failing to locate or initialize the module.

  • ✓

    The module is a C extension that fails to load.

    Why this is correct

    A C extension is a binary shared library (e.g., .so or .pyd) that Python loads through the dynamic linker. If a required dependency is missing, a symbol is unresolved, or the binary ABI is incompatible, the OS raises a low-level loader error which Python catches and re-raises as ImportError. The file may exist and be syntactically valid, but the extension's initialization cannot complete, making this a legitimate import-time failure mode.

  • ✓

    The module has a circular import.

    Why this is correct

    A circular import occurs when module A imports module B while B (directly or indirectly) imports A before A has finished initializing. At that point, sys.modules contains a partially initialized A, so when B attempts 'from A import name', the import system cannot find the not-yet-defined name and raises ImportError (or AttributeError in some cases). This is an execution-order problem, not a path or file problem, and it can be tricky because the ImportError is raised inside the partially executed module.

  • ✓

    The module is not in the search path.

    Why this is correct

    The module's file does exist somewhere on disk, but the import system cannot find it because its directory is absent from sys.path. Python searches sys.path in order for the module's location; if none of the directories (or ZIP archives) contain a matching file or package directory, an ImportError is raised (specifically, ModuleNotFoundError in Python 3.6+). This commonly happens due to a misconfigured PYTHONPATH, not installing the package into the active environment, or running code without the current directory on sys.path.

  • ✗

    The module's __init__.py is empty.

    Why it's wrong here

    An empty __init__.py is perfectly valid and is, in fact, a normal way to mark a directory as a regular package in Python (before PEP 420 namespace packages). When Python imports the package, it executes __init__.py; if the file is empty, it simply has no side effects, and the import completes successfully. The presence or absence of content in __init__.py never causes ImportError; it only affects whether the package defines any import-time initialization behavior.

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.