Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when using importlib.metadata.version #28

Closed
gsemet opened this issue Jun 21, 2023 · 2 comments
Closed

Crash when using importlib.metadata.version #28

gsemet opened this issue Jun 21, 2023 · 2 comments

Comments

@gsemet
Copy link

gsemet commented Jun 21, 2023

Hi

When using

from importlib.metadata import version
version("name_of_my_package")

I get a crash importlib.metadata.PackageNotFoundError: No package metadata was found for name_of_my_package

I first create the wheel of my package and then create the

   zipapps --output dist/$(PACKAGE_NAME).pyz -u=AUTO
        -p '/usr/bin/env python3'
        -m name_of_my_package.cli:cli 
        -r dist/prod-requirements.txt 
        dist/name_of_my_package-*.whl

I think name_of_my_package.whl is well installed I see it in the pip install output, but it seems like the importlib does not find it when executed in the pyz generated by zipapps. It works with shiv.

@ClericPy
Copy link
Owner

try use -u=* to unzip all the files, this is similar to shiv may make some sense

@TsXor
Copy link

TsXor commented Jun 3, 2024

This is because zipapps does not include package metadata.
For example, let's run python -m zipapps -o psutil.pyz -u AUTO psutil and take a look inside generated psutil.pyz.
You'll find that only module directory psutil is present, but metadata directory (in my case psutil-5.9.2.dist-info) is missing. That's why importlib.metadata complains.
To fix that, you can use lazy install, which installs required packages at runtime.
Alternatively, you can tell zipapps to use a specific cache directory and copy package metadata to there ahead of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants