pyheap icon indicating copy to clipboard operation
pyheap copied to clipboard

ModuleNotFoundError: No module named 'elftools'

Open tazle opened this issue 2 years ago • 1 comments

After some trial and error, I managed to build something that looks like pyheap_dump using make dist under pyheap/.

However, when I run it, I get:

$ python3 dist/pyheap_dump -h
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/root/.pex/unzipped_pexes/d6692ccf46272ba36e5f9de24e94de435125b194/__main__.py", line 103, in <module>
    bootstrap_pex(__entry_point__, execute=__execute__, venv_dir=__venv_dir__)
  File "/root/.pex/unzipped_pexes/d6692ccf46272ba36e5f9de24e94de435125b194/.bootstrap/pex/pex_bootstrapper.py", line 600, in bootstrap_pex
    pex.PEX(entry_point).execute()
  File "/root/.pex/unzipped_pexes/d6692ccf46272ba36e5f9de24e94de435125b194/.bootstrap/pex/pex.py", line 551, in execute
    sys.exit(self._wrap_coverage(self._wrap_profiling, self._execute))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.pex/unzipped_pexes/d6692ccf46272ba36e5f9de24e94de435125b194/.bootstrap/pex/pex.py", line 458, in _wrap_coverage
    return runner(*args)
           ^^^^^^^^^^^^^
  File "/root/.pex/unzipped_pexes/d6692ccf46272ba36e5f9de24e94de435125b194/.bootstrap/pex/pex.py", line 489, in _wrap_profiling
    return runner(*args)
           ^^^^^^^^^^^^^
  File "/root/.pex/unzipped_pexes/d6692ccf46272ba36e5f9de24e94de435125b194/.bootstrap/pex/pex.py", line 594, in _execute
    return self.execute_entry(
           ^^^^^^^^^^^^^^^^^^^
  File "/root/.pex/unzipped_pexes/d6692ccf46272ba36e5f9de24e94de435125b194/.bootstrap/pex/pex.py", line 774, in execute_entry
    return self.execute_entry_point(entry_point)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.pex/unzipped_pexes/d6692ccf46272ba36e5f9de24e94de435125b194/.bootstrap/pex/pex.py", line 791, in execute_entry_point
    runner = entry_point.resolve()
             ^^^^^^^^^^^^^^^^^^^^^
  File "/root/.pex/unzipped_pexes/d6692ccf46272ba36e5f9de24e94de435125b194/.bootstrap/pex/dist_metadata.py", line 730, in resolve
    module = importlib.import_module(self.module)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/root/.pex/unzipped_pexes/d6692ccf46272ba36e5f9de24e94de435125b194/pyheap_dump.py", line 50, in <module>
    from python_checker import check_if_python
  File "/root/.pex/unzipped_pexes/d6692ccf46272ba36e5f9de24e94de435125b194/python_checker.py", line 19, in <module>
    from elftools.elf import elffile
ModuleNotFoundError: No module named 'elftools'

It looks like pyheap/build/requirements.txt is empty. If I add pyelftools there, I can run:

$ python3 dist/pyheap_dump -h
usage: pyheap_dump [-h] (--pid PID | --docker-container DOCKER_CONTAINER) --file FILE [--str-repr-len STR_REPR_LEN] [--ignore-compatibility-checks] [--force-shadow]

Dump heap.

options:
  -h, --help            show this help message and exit
  --pid PID, -p PID     target process PID
  --docker-container DOCKER_CONTAINER
                        target Docker container
  --file FILE, -f FILE  heap file name
  --str-repr-len STR_REPR_LEN
                        max length of string representation of objects (-1 disables it)
  --ignore-compatibility-checks
                        ignore various compatibility checks for the target process
  --force-shadow        force shadowing of the Python executable directory (e.g. /usr/bin); nsenter + unshare will also be forced

tazle avatar Aug 18 '23 08:08 tazle

I think the trouble was I first ran make dist before I had poetry installed, so build/requirements.txt got created as empty, and didn't get recreated because poetry.lock didn't change.

tazle avatar Aug 18 '23 08:08 tazle