Interview questions

Fix ModuleNotFoundError: No module named 'imp' in Python

August 28, 2025Updated October 19, 20268 min read
Why Is Python Raising "No Module Named Imp" And How Does It Impact Your Interview Performance

Python 3.12 removed the imp module. Find what still imports it, then port it to importlib, upgrade the library or run Python 3.11. Swap table inside.

You see ModuleNotFoundError: No module named 'imp' because some code is running on Python 3.12 or newer and still imports imp. The module was deprecated in Python 3.4 and removed in 3.12, and its jobs moved to importlib. You cannot pip install it back. The fix depends on whose code does the import:

  • Your code: swap each imp call for its importlib equivalent (table below).
  • A library or tool: upgrade it, or remove the old version pin that holds it back.
  • Neither, today: run the project in a Python 3.11 virtual environment while you sort it out.

Step 1: find out whose code imports imp

Read the bottom of the traceback. The file named just above the error is the one doing the import. Here is a shortened version of the traceback reported in the issue tracker of thefuck, a command-line tool:

  File ".../thefuck/conf.py", line 1, in <module>
    from imp import load_source
ModuleNotFoundError: No module named 'imp'

That path tells you the problem is inside an installed package, not your project. As a rule:

  • If the path points into your own project folder, go to Fix 1.
  • If it points into site-packages, it is a third-party package or a tool you installed. Go to Fix 2.

Before changing anything, confirm which interpreter is actually running. A virtual environment can use a different Python from the one on your PATH:

python -c "import sys; print(sys.executable, sys.version)"

To list every place your own code touches imp:

grep -rnw imp --include='*.py' .

Fix 1: replace imp with importlib in your own code

The Python 3.12 release notes give a one-to-one table for the functions that have a replacement:

  • Old imp call — Use instead
  • imp.reload(module) — importlib.reload(module)
  • imp.load_module() — importlib.import_module()
  • imp.find_module() — importlib.util.find_spec()
  • imp.new_module(name) — types.ModuleType(name)
  • imp.cache_from_source() — importlib.util.cache_from_source()
  • imp.source_from_cache() — importlib.util.source_from_cache()
  • imp.get_magic() — importlib.util.MAGIC_NUMBER
  • imp.get_tag() — sys.implementation.cache_tag
  • imp.get_suffixes() — importlib.machinery.SOURCE_SUFFIXES, EXTENSION_SUFFIXES and BYTECODE_SUFFIXES
  • imp.NullImporter — insert None into sys.path_importer_cache
  • imp.load_source() — the function below

The most common case is a reload, which is a one-word change:

# Python 3.11 and older
import imp
imp.reload(config)

# Python 3.12 and newer
import importlib
importlib.reload(config)

Watch one behaviour change when you swap find_module(). The old function raised ImportError when it could not find a module; find_spec() returns None instead. A try/except ImportError block written for the old call will no longer catch the miss, so test for None.

A few functions were removed with no replacement: imp.load_compiled(), imp.load_dynamic(), imp.load_package(), imp.init_builtin() and the import-lock functions. Code that relies on them needs a redesign rather than a swap.

Replacing imp.load_source()

load_source() loads a Python file from a path; it is the call in the thefuck traceback above. This is the replacement from the Python 3.12 release notes:

import importlib.util
import importlib.machinery

def load_source(modname, filename):
    loader = importlib.machinery.SourceFileLoader(modname, filename)
    spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
    module = importlib.util.module_from_spec(spec)
    # The module is always executed and not cached in sys.modules.
    # Uncomment the following line to cache the module.
    # sys.modules[module.__name__] = module
    loader.exec_module(module)
    return module

Keep the explicit loader= argument. Shorter snippets often leave it out, including the "importing a source file directly" recipe in the importlib docs, and that works only when the file name ends in a suffix Python recognises, such as .py. For anything else, say a settings.conf file, spec_from_file_location() returns None (you can see this in its source code), and the next line fails with AttributeError: 'NoneType' object has no attribute 'loader'.

If other code later does import on the same module name, uncomment the sys.modules line (and add import sys), or that code will load a fresh copy.

Fix 2: upgrade the library that imports it

Often the import sits in a dependency, not your own code. Two cases from public issue trackers show the usual shape:

  • plotly's contributor setup hit the error on Python 3.12 and told developers to create their environment with Python 3.11 instead; the PR also raised the old pytest==3.5.1 pin to pytest==8.1.1, which fixed a separate test-runner error on 3.11.
  • In anomalib's tracker, installs on Python 3.12 failed because the pinned wandb range pulled in an older release that imported imp; a pull request proposed removing the upper limit on wandb (it was closed without merging).

In both cases an old version pin or upper limit was part of the problem, so check your requirements file or lock file before anything else, then upgrade:

pip show <package>
pip install --upgrade <package>

Sometimes there is no fixed release yet. In the thefuck issue, users on Python 3.12 got it working by installing straight from the project's main branch, and in December 2025 a commenter noted that a plain pip install thefuck still failed on 3.12 and newer. Check the package's issue tracker: the fix may be merged but unreleased, or someone may have posted a patch.

Expect a second error after the first one clears. Python 3.12 also removed distutils, and virtual environments created with venv no longer come with setuptools preinstalled. If you next see No module named 'distutils', run pip install setuptools inside the environment, which still provides it.

Fix 3: run the project on Python 3.11

Use this when a dependency you cannot change still imports imp, or when you have a deadline. Create a virtual environment with 3.11 and reinstall into it:

python3.11 -m venv .venv        # macOS / Linux
py -3.11 -m venv .venv          # Windows

Activate it (source .venv/bin/activate on macOS or Linux, .venv\Scripts\activate.bat on Windows) and install your requirements again. Python 3.11 is scheduled to receive security fixes until October 2027, so treat this as a stopgap with an end date, not a home.

What not to do

  • `pip install imp`. There is no such package to install. imp was part of the standard library, so the command fails.
  • Reach for zombie-imp by default. It is a real package that restores a copy of the removed module, but its own README tells you not to use it and to port the project that needs it to importlib. It can get a throwaway script running; it should not end up in code other people install.
  • Patch files inside `site-packages`. The next install or upgrade overwrites your edit, and nobody else on the project gets it.

If it shows up in a take-home or a live coding round

A starter repository written a few years ago may assume an older Python. Before you install anything for a take-home, check the README or pyproject.toml for a required version and compare it with python --version. If they clash, set up a 3.11 environment, and add one line to your submission saying which version you used and why. That line tells the reviewer you understood the problem instead of fighting it.

If the error appears in a shared environment during a live round, name it in a sentence and offer a choice: "This library still imports imp, which Python 3.12 removed. I can switch the call to importlib or run it on 3.11; which would you prefer?" That keeps the conversation on your reasoning, which is what a technical round is assessing. For the coding problems themselves, see our notes on IBM's coding assessment and common LeetCode-style questions.

If you want to rehearse explaining Python fixes out loud before a coding round, Verve AI's Coding Copilot reads a problem from a screen capture, returns a solution in 21+ programming languages including Python, and has Edge Case and Complexity quick actions to practise the follow-up questions.

Quick answers

Where is the official documentation for the removal? In "What's New in Python 3.12", under Removed, then imp. It contains the full replacement table. The Python 3.11 imp page also carries the notice: deprecated since 3.4, removed in 3.12.

Which Python versions raise this error? Python 3.12 and every later version. On 3.11 and earlier, import imp still works, although the module has been deprecated since 3.4.

Is importlib harder to use? For reloads and named imports it is a one-line swap. Loading a file from a path takes the few lines shown above.

Sources

  • imp removal in 3.12, replacement table, load_source recipe, functions with no replacement, distutils removal (PEP 632), setuptools no longer preinstalled in venvs: https://docs.python.org/3/whatsnew/3.12.html
  • imp deprecated since 3.4, scheduled removal in 3.12; find_module raises ImportError; reload deprecation note: https://docs.python.org/3.11/library/imp.html
  • find_spec returns None when no spec is found; import_module, reload, module_from_spec, spec_from_file_location: https://docs.python.org/3/library/importlib.html
  • spec_from_file_location returns None when no loader matches the file suffix: https://raw.githubusercontent.com/python/cpython/3.13/Lib/importlib/_bootstrap_external.py
  • thefuck traceback (conf.py, from imp import load_source), install-from-master workaround, December 2025 comment from the issue reporter saying plain pip install thefuck still fails on 3.12+: https://github.com/nvbn/thefuck/issues/1434
  • plotly hitting the error on Python 3.12 and moving contributors to 3.11; pytest 3.5.1 pin raised to 8.1.1 for a separate 3.11 error; pip install imp fails: https://github.com/plotly/plotly.py/pull/4605
  • anomalib PR proposing removal of the wandb upper bound because older wandb imported imp (closed without merging): https://github.com/openvinotoolkit/anomalib/pull/2322
  • zombie-imp README (copy of the removed module; advises porting instead): https://github.com/encukou/zombie-imp
  • zombie-imp package on PyPI: https://pypi.org/project/zombie-imp/
  • Python 3.11 end of life scheduled for 2027-10: https://devguide.python.org/versions/
  • Creating a virtual environment and activation commands: https://docs.python.org/3/library/venv.html
  • Windows py launcher version selection (py -3.x): https://docs.python.org/3/using/windows.html
  • Verve Coding Copilot (screen capture, 21+ languages, quick actions): https://docs.vervecopilot.com/features/coding-copilot
R

Ryan

CEO of Verve AI

Related reads

Explore Related Interview Guides

Why Using A Hard Working Synonym Can Make Your Professional Communication Shine
October 10, 2025Interview prep guide

Why Using A Hard Working Synonym Can Make Your Professional Communication Shine

Get insights on working hard synonym with proven strategies and expert tips.

Read guide
Why Using A Specific Passionateness Synonym Might Be Your Edge In Professional Conversations
October 10, 2025Interview prep guide

Why Using A Specific Passionateness Synonym Might Be Your Edge In Professional Conversations

Get insights on passionateness synonym with proven strategies and expert tips.

Read guide
Why Using Computer Assisted Interview Concepts Can Boost Your Interview Performance
July 3, 2025Interview prep guide

Why Using Computer Assisted Interview Concepts Can Boost Your Interview Performance

Get insights on computer assisted interview with proven strategies and expert tips.

Read guide
Why What Am I Passionate About Might Be The Most Insightful Interview Question
July 4, 2025Interview prep guide

Why What Am I Passionate About Might Be The Most Insightful Interview Question

Get insights on what am i passionate about with proven strategies and expert tips.

Read guide
Why What Are You Looking For In Your Next Role Is More Than Just A Question
May 10, 2026Interview prep guide

What Are You Looking for in Your Next Role? A Simple Answer Formula

Use a simple 3-part formula for what are you looking for in your next role, and answer with mid-level examples that sound grounded and role-aware.

Read guide
Why What Do Estheticians Do Is About More Than Just Skin Care In Interviews
September 4, 2025Interview prep guide

Why What Do Estheticians Do Is About More Than Just Skin Care In Interviews

Get insights on what do estheticians do with proven strategies and expert tips.

Read guide
Why What Is A Stay Interview Might Be Your Most Important Career Conversation
July 9, 2025Interview prep guide

Why What Is A Stay Interview Might Be Your Most Important Career Conversation

Get insights on what is a stay interview with proven strategies and expert tips.

Read guide
Why What Is Companion Mode In Google Meet Might Be Your Secret To Better Virtual Interviews
October 10, 2025Interview prep guide

Why What Is Companion Mode In Google Meet Might Be Your Secret To Better Virtual Interviews

Get insights on what is companion mode in google meet with proven strategies and expert tips.

Read guide
Why What Is Your Biggest Accomplishment Matters More Than You Think In Professional Settings
July 16, 2025Interview prep guide

Why What Is Your Biggest Accomplishment Matters More Than You Think In Professional Settings

Get insights on what is your biggest accomplishment with proven strategies and expert tips.

Read guide

Ace your live interviews with AI support!

Get Started For Free

Available on Mac, Windows, browser and mobile