[Fixed] Python ModuleNotFoundError: No module named 'elftools.common.py3compat' – Python

by
Maya Patel
llama-cpp-python pwntools

Quick Fix: Downgrade the current version of pyelftools to 0.29 to resolve the ModuleNotFoundError. Run the following commands in your terminal:

pip uninstall pyelftools -y
pip install pyelftools==0.29

The Problem:

Issue installing ‘pwntools’ in WSL 2 (Ubuntu 22.04) on Windows 11.

Installation Steps:

  1. apt-get update
  2. apt-get install python3 python3-pip python3-dev git libssl-dev libffi-dev build-essential
  3. python3 -m pip install –upgrade pip
  4. python3 -m pip install –upgrade pwntools

Error encountered during testing:
Traceback (most recent call last):
File , line 1, in
File "/home/kimminjun514/.local/lib/python3.10/site-packages/pwn/init.py", line 4, in
from pwn.toplevel import *
File "/home/kimminjun514/.local/lib/python3.10/site-packages/pwn/toplevel.py", line 23, in
from pwnlib import *
File "/home/kimminjun514/.local/lib/python3.10/site-packages/pwnlib/dynelf.py", line 57, in
from pwnlib import elf
File "/home/kimminjun514/.local/lib/python3.10/site-packages/pwnlib/elf/init.py", line 9, in
from pwnlib.elf.corefile import Core
File "/home/kimminjun514/.local/lib/python3.10/site-packages/pwnlib/elf/corefile.py", line 79, in
from elftools.common.py3compat import bytes2str
ModuleNotFoundError: No module named ‘elftools.common.py3compat’

Tried solutions:

  • Reinstalling WSL 2
  • Extensive web searches failed to resolve the issue.

The Solutions:

Solution 1: Downgrading pyelftools

The issue arises due to incompatibility between the installed version of `pyelftools` and `pwntools`. To resolve this, follow these steps:

  1. Check `pyelftools` Version:
    Run the following command to check the installed version of `pyelftools`:
    “`
    pip show pyelftools
    “`

    It should display the output similar to:
    “`
    Name: pyelftools
    Version: 0.30

    “`

    If the version is `0.30`, proceed to the next step; otherwise, you can skip to the last step.
  2. Downgrade `pyelftools` to Version 0.29:
    Run the following command to downgrade `pyelftools` to version 0.29:
    “`
    pip uninstall pyelftools -y
    pip install pyelftools==0.29
    “`

    This command will uninstall the current version of `pyelftools` and install version 0.29.
  3. Reinstall `pwntools`:
    Once you have downgraded `pyelftools`, reinstall `pwntools` using the following command:
    “`
    pip install –upgrade pwntools
    “`

    This command will reinstall the latest version of `pwntools`, which is compatible with `pyelftools` version 0.29.

After completing these steps, you should be able to use `pwntools` without encountering the `ModuleNotFoundError` exception.

Q&A

What could be causing the ModuleNotFoundError?

Check the version of pyelftools. Version 0.29 may work.

Is a new computer needed?

No, this issue can be resolved.

Video Explanation:

The following video, titled "No Module Named Requests FIXED - Pycharm or Komodo edit ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

Comments85 ; Fix ModuleNotFoundError (No Module Named Requests) Python Import Error (If Installed / If Exists). Ghost Together · 16K views ; How ...