eliben / pyelftools

Parsing ELF and DWARF in Python
Other
2.03k stars 512 forks source link

Debug raising error when running as packaged app by pyinstaller #575

Closed zlt999 closed 1 week ago

zlt999 commented 3 weeks ago

I run the packaged app by pyinstaller on windows platform, and get error raised as below:

Traceback (most recent call last):
  File "<frozen __main__>", line 3, in <module>
  File "<frozen src.main>", line 7, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 378, in exec_module
  File "main_window.py", line 11, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 378, in exec_module
  File "bincopy.py", line 18, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 378, in exec_module
  File "elftools\elf\elffile.py", line 17, in <module>
AttributeError: module 'resource' has no attribute 'getpagesize'
[PYI-26572:ERROR] Failed to execute script 'main' due to unhandled exception!

Still not sure where this resouce.py come from. I use dir() and get output as below:

['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

This resource.py seems to be empty.

After all, I changed the source code in elffile.py and the problem is gone.

sevaa commented 3 weeks ago

IIRC, resource is a built-in library in CPython.

sevaa commented 1 week ago

@eliben This looks inoffensive enough. PAGESIZE, strictly speaking, is not even particularly necessary - it's only used for reading chunks to be decompressed, a hard coded buffer size would do just as well.

eliben commented 1 week ago

@sevaa agreed, would you like to send a quick PR to remove all that PAGESIZE mess? I suppose something like a 4 KiB buffer size would do