Skip to content

importing pkg_resources fails #134

@lithp

Description

@lithp

I believe that pkg_resouces is simply incompatible with pyoxidizer, but I've only been playing with pyoxidizer for a few hours so maybe someone here knows better. Is there a way to get pkg_resources to work? It's used in quite a few places by the tool I'm trying to package up!

If I init a new project and then make two changes:

[[packaging_rule]]
type = "pip-install-simple"
package = "setuptools>=36.2.0"

[[embedded_python_run]]
mode = "eval"
code = "import pkg_resources"

Then pyoxidizer run gives me a fun error:

Traceback (most recent call last):
  File "linecache", line 95, in updatecache
FileNotFoundError: [Errno 2] No such file or directory: 'pkg_resources._vendor.pyparsing'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "pkg_resources", line 84, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "pkg_resources.extern", line 43, in load_module
  File "pkg_resources._vendor.packaging.requirements", line 9, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "pkg_resources.extern", line 43, in load_module
  File "pkg_resources._vendor.pyparsing", line 4756, in <module>
  File "pkg_resources._vendor.pyparsing", line 1284, in setParseAction
  File "pkg_resources._vendor.pyparsing", line 1066, in _trim_arity
  File "pkg_resources._vendor.pyparsing", line 1050, in extract_stack
  File "traceback", line 211, in extract_stack
  File "traceback", line 363, in extract
  File "traceback", line 285, in line
  File "linecache", line 16, in getline
  File "linecache", line 47, in getlines
  File "linecache", line 103, in updatecache
  File "<frozen importlib._bootstrap_external>", line 566, in decode_source
AttributeError: 'memoryview' object has no attribute 'decode'
error: cargo run failed

Here's the relevant code:

https://github.com/python/cpython/blob/5e1400a6bcbb3350a6665176980a2b8343075c63/Lib/linecache.py#L94-L105

It looks like python is trying to stat the file. The stat fails because pyoxidizer is like that. Then, something deep inside importlib is attempting to use the memoryview which pyoxidizer passes in and failing, probably because it expects straight bytes?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions