question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nuitka doesn't support pkg_resources.get_distribution

See original GitHub issue

Sometimes code will check installed package versions with require or use the version information of installed packages for outputs. For standalone packages that does not work:

__version__ = pkg_resources.get_distribution('requests').version

However, by teaching pkg_resources about our meta path based importer, we could convince it to provide the information even when egg data, etc. has been lost.

The source of the information is easy to get:

env = pkg_resources.Environment()
env.scan()
print(env._distmap)

This produces a dictionary with the information to use to produce Distribution objects at run time.

This apparently mostly does the job, but is bare of robustness:

def get_importer(path_item):
    return sys.meta_path[0]

def my_finder(a,b,c):
    yield pkg_resources.Distribution(project_name = "requests", version = "5")

pkg_resources.register_finder(type(sys.meta_path[0]), my_finder)
pkg_resources.get_importer = get_importer

__version__ = pkg_resources.get_distribution('requests').version

This code could become a post-load for pkg_resources to monkey patch it for finding resources hidden in the meta path based loader. Our meta path based loader should not be assumed to be only one (it is not for Python3 anyway), but directly accessed.

Also maybe it could read the distribution data from disk, to avoid caching issues, and it’s nicer to read that way probably too.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kayhayencommented, Nov 27, 2021

It’s automatically enabled.

1reaction
kayhayencommented, Nov 27, 2021

There is a plugin in Nuitka that detects these kinds of version stuff, and resolves them now at compile time to the correct value, avoiding any runtime code, which makes this a solved issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuitka-chat/community - Gitter
DistributionNotFound: The 'beagle' distribution was not found and is required ... This time I had more luck - application show the help, and...
Read more >
User Manual - Nuitka
No information is available for this page.
Read more >
Intro to Nuitka: A better way to compile and distribute Python
You can use Nuitka to compile Python programs to standalone executables, then redistribute them without the Python runtime.
Read more >
Ubuntu Manpage: nuitka - the Python compiler
--include-package=PACKAGE Include a whole package. Give as a Python namespace, e.g. ``some_package.sub_package`` and Nuitka will then find it and include it ...
Read more >
nuitka can not find library distribution - Stack Overflow
I am able to run the python script that means all the imported packages are present. But when I try to build exe...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found