hobbits icon indicating copy to clipboard operation
hobbits copied to clipboard

analyzing Kaitai Structs fails on missing 'pkg_ressources' python module

Open derVedro opened this issue 3 years ago • 3 comments

If your system python is not 3.9 you're pretty screwed on analizing Kaitai Structs:

Python stderr:
Traceback (most recent call last):
  File "/tmp/HobbitsPythonrBHuvX/thescript.py", line 162, in parse_data
    struct_module = importlib.__import__(package_name, fromlist=[class_name])
  File "<frozen importlib._bootstrap>", line 1109, in __import__
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/tmp/hobbits-GGgAzl/png.py", line 3, in <module>
    from pkg_resources import parse_version
ModuleNotFoundError: No module named 'pkg_resources'

derVedro avatar Nov 26 '22 01:11 derVedro

You can hack around and install pip (which comes with setuptools and pkg_resources) into your hobbits-cpython directory tree.

First get the pip installer script into your temp directory: $ wget https://bootstrap.pypa.io/get-pip.py -P /tmp

Then install pip into your hobbits-cpython $ hobbits-cpython/bin/python3.9 /tmp/get-pip.py

The requeired packages are in hobbits-cpython/lib/python3.9/site-packages now, so you're done.

derVedro avatar Nov 26 '22 01:11 derVedro

yeah, looks like the built-in python pip is messed up in some of the builds :( ugh

Thanks for posting the workaround! I might just put something like that in the build steps because building Python reliably with that stuff seemed weirdly error-prone in the CI I had set up.

hello-adam avatar Nov 27 '22 15:11 hello-adam

BTW, Python parsers generated by Kaitai Struct compiler v0.10 do not import pkg_resources anymore, see Kaitai Struct v0.10 release notes:

  • Notable improvements:
    • (...)
    • Python: generated parsers no longer import pkg_resources, which caused performance and usability issues (#804) — the runtime library API version check now compares tuples instead

generalmimon avatar Dec 20 '22 14:12 generalmimon