try/except usage of importlib.metadata/importlib_metadata does not work on 3.7 or lower
See original GitHub issueHello
I used nuitka 0.7.7 for a long time without problems. After upgrade to 1.0.3 I started to receive an error (importlib_metadata.PackageNotFoundError) in my project that previously worked correct.
importlib_metadata.PackageNotFoundError: No package metadata was found for prettytable
Nuitka version:
1.0.3
Commercial: None
Python: 3.6.8 (default, Aug 13 2020, 07:46:32)
Flavor: Fedora Python
Executable: /home/rlm_dev/ushd/sds_discovery/bin/python
OS: Linux
Arch: x86_64
Distribution: Rhel (based on Fedora) 7.9
Pip list:
Package Version
------------------ ---------
attrs 21.4.0
boto3 1.23.10
botocore 1.26.10
certifi 2022.6.15
charset-normalizer 2.0.12
idna 3.3
importlib-metadata 4.8.3
jmespath 0.10.0
Nuitka 1.0.3
orderedset 2.0.3
pip 21.3.1
prettytable 2.5.0
psycopg2-binary 2.9.3
python-dateutil 2.8.2
requests 2.27.1
requests-aws 0.1.8
rgwadmin 2.3.1
s3transfer 0.5.2
setuptools 39.2.0
six 1.16.0
typing_extensions 4.1.1
urllib3 1.26.9
wcwidth 0.2.5
zipp 3.6.0
I tested some versions of nuitka and found out that last worked version is 0.8.4 and problem started from 0.9. Test program test.py:
import prettytable
def main():
print("hello world")
return
if __name__ == '__main__':
main()
Nuitka 1.0.3:
(sds_discovery) [[rlm_dev@tkles](mailto:rlm_dev@tkles) /home/rlm_dev/ushd/sds_discovery/sds/sds/sds_discovering]$ python -m nuitka --standalone test.py
Nuitka-Options:INFO: Used command line options: --standalone test.py
Nuitka:INFO: Starting Python compilation with Nuitka '1.0.3' on Python '3.6' commercial grade 'not installed'.
Nuitka-Plugins:INFO: multiprocessing: Injecting pre-module load code for module 'multiprocessing':
Nuitka-Plugins:INFO: multiprocessing: Monkey patching "multiprocessing" load environment.
Nuitka-Plugins:INFO: multiprocessing: Injecting post-module load code for module 'multiprocessing':
Nuitka-Plugins:INFO: multiprocessing: Monkey patching "multiprocessing" for compiled methods.
Nuitka:INFO: Completed Python level compilation and optimization.
Nuitka:INFO: Generating source code for C backend compiler.
Nuitka:INFO: Running data composer tool for optimal constant value handling.
Nuitka:INFO: Running C compilation via Scons.
Nuitka-Scons:INFO: The provided gcc is too old, switching to its g++ instead.
Nuitka-Scons:INFO: Backend C compiler: g++ (g++).
Nuitka-Scons:INFO: Backend linking program with 22 files (no progress information available).
Nuitka-Scons:INFO: Compiled 22 C files using ccache.
Nuitka-Scons:INFO: Cached C files (using ccache) with result 'cache hit': 6
Nuitka-Scons:INFO: Cached C files (using ccache) with result 'cache miss': 15
Nuitka:INFO: Keeping build directory 'test.build'.
Nuitka:INFO: Successfully created 'test.dist/test'.
Traceback (most recent call last):
File "/home/rlm_dev/ushd/sds_discovery/sds/sds/sds_discovering/test.dist/test.py", line 1, in <module>
File "/home/rlm_dev/ushd/sds_discovery/sds/sds/sds_discovering/test.dist/prettytable/__init__.py", line 52, in <module prettytable>
File "/home/rlm_dev/ushd/sds_discovery/sds/sds/sds_discovering/test.dist/importlib_metadata/__init__.py", line 990, in version
File "/home/rlm_dev/ushd/sds_discovery/sds/sds/sds_discovering/test.dist/importlib_metadata/__init__.py", line 963, in distribution
File "/home/rlm_dev/ushd/sds_discovery/sds/sds/sds_discovering/test.dist/importlib_metadata/__init__.py", line 542, in from_name
importlib_metadata.PackageNotFoundError: No package metadata was found for prettytable
Nuitka 0.8.4:
INFO: Start nuitka
Nuitka-Options:INFO: Used command line options: --standalone sds/sds_discovering/scripts/sds_discovery.py
Nuitka:INFO: Starting Python compilation with Nuitka '0.8.4' on Python '3.6' commercial None.
Nuitka-Plugins:INFO: anti-bloat: Handling module 'certifi.core' with 1 change(s) for: avoid using importlib.resources without need.
Nuitka-Plugins:INFO: multiprocessing: Injecting pre-module load code for module 'multiprocessing':
Nuitka-Plugins:INFO: multiprocessing: Monkey patching "multiprocessing" load environment.
Nuitka-Plugins:INFO: multiprocessing: Injecting post-module load code for module 'multiprocessing':
Nuitka-Plugins:INFO: multiprocessing: Monkey patching "multiprocessing" for compiled methods.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'urllib3' added 'urllib3,urllib3._collections,urllib3.connection,urllib3.connectionpool,urllib3.contrib,urllib3.contrib.appengine,urllib3.exceptions,urllib3.fields,urllib3.filepost,urllib3.packages,urllib3.packages.six,urllib3.poolmanager,urllib3.request,urllib3.response,urllib3.util,urllib3.util.connection,urllib3.util.queue,urllib3.util.request,urllib3.util.response,urllib3.util.retry,urllib3.util.ssl_,urllib3.util.timeout,urllib3.util.url,urllib3.util.wait,urllib.error,urllib.parse,urllib.request,urllib.response'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'boto3' added 'boto3.ec2,boto3.ec2.createtags,boto3.ec2.deletetags,boto3.dynamodb,boto3.s3,boto3.s3.inject,boto3.s3.transfer'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'zipfile' added 'py_compile'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'urllib.request' added 'http.client,http.cookiejar'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'socket' added '_socket'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'shelve' added 'dbm.dumb'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'pathlib' added 'ntpath,posixpath'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'ctypes' added '_ctypes'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module '_asyncio' added 'asyncio'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'locale' added '_bootlocale'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'encodings' added 'encodings.idna,encodings.base64_codec,encodings.hex_codec,encodings.rot_13'.
Nuitka:INFO: Completed Python level compilation and optimization.
Nuitka:INFO: Generating source code for C backend compiler.
Nuitka:INFO: Running data composer tool for optimal constant value handling.
Nuitka:INFO: Running C compilation via Scons.
Nuitka-Scons:INFO: The provided gcc is too old, switching to its g++ instead.
Nuitka-Scons:INFO: Backend C compiler: g++ (g++).
Nuitka-Scons:INFO: Backend linking program (no progress information available).
Nuitka-Scons:INFO: Compiled 273 C files using ccache.
Nuitka-Scons:INFO: Cached C files (using ccache) with result 'cache hit': 272
Nuitka-Plugins:INFO: data-files: Included 16 data files due to package data directory 'data' for 'boto3'.
Nuitka-Plugins:INFO: data-files: Included data file 'botocore/cacert.pem' due to package data for 'botocore'.
Nuitka-Plugins:INFO: data-files: Included 906 data files due to package data directory 'data' for 'botocore'.
Nuitka-Plugins:INFO: data-files: Included data file 'certifi/cacert.pem' due to package data for 'certifi'.
Nuitka:INFO: Keeping build directory 'sds_discovery.build'.
Nuitka:INFO: Successfully created 'sds_discovery.dist/sds_discovery'.
(sds_discovery) [[rlm_dev@tkles](mailto:rlm_dev@tkles) /home/rlm_dev/ushd/sds_discovery/sds/sds/sds_discovering]$ ./test.dist/test
hello world
In addition I tried some options for solving the problem. Without success.
python -m nuitka --standalone --include-package=prettytable test.py
python -m nuitka --standalone --follow-stdlib test.py
python -m nuitka --standalone --full-compat test.py
python -m nuitka --standalone --disable-plugin=anti-bloat test.py
Could you help me to solve this problem?
Thanks.
Issue Analytics
- State:
- Created a year ago
- Comments:13 (12 by maintainers)
Top Results From Across the Web
Using importlib.metadata — Python 3.11.1 documentation
importlib_metadata is a library that provides access to the metadata of an installed Distribution Package, such as its entry points or its top-level...
Read more >ImportError: cannot import name 'metadata' from 'importlib'
1) I cannot figure out why the presence of a line from importlib import metadata , in a distribution where importlib does not...
Read more >importlib-metadata - PyPI
importlib -metadata 5.2.0 ... Usage. See the online documentation for usage details. ... Report bugs at: https://github.com/python/importlib_metadata/issues.
Read more >How to Check 'importlib-metadata' Package Version in Python?
Patch releases ( 0.1.0 to 0.1.1 ) are used for smaller bug fixes that are backward ... In some instances, this will not...
Read more >5. The import system — documentation Python 3.7.0a0
The importlib module provides a rich API for interacting with the import system. ... Namespace packages do not use an ordinary list for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It seems, this pattern is not working for static optimization in Nuitka:
Part of the 1.2 release that was made a while ago.