Skip to content
This repository was archived by the owner on Feb 25, 2024. It is now read-only.

cannot import name 'EntryPoints' from 'importlib_metadata' #49

Open
piercus opened this issue Jul 6, 2023 · 1 comment
Open

cannot import name 'EntryPoints' from 'importlib_metadata' #49

piercus opened this issue Jul 6, 2023 · 1 comment

Comments

@piercus
Copy link

piercus commented Jul 6, 2023

I've faced an error cannot import name 'EntryPoints' from 'importlib_metadata' inside the lambda function.

Investigation

I have found aws/aws-lambda-python-runtime-interface-client#61 and aws/aws-lambda-python-runtime-interface-client#61

Problem from awslambdaric which depends on an old version of importlib-metadata (2.0.0) which is overriding the version use by

Switching to python 3.8 fixed the issue.

@bvsam
Copy link
Contributor

bvsam commented Dec 10, 2023

I encounter the same error. When running bentoctl build with a bento and a basic pre-generated AWS lambda deployment_config.yaml file, I encounter the following error as the docker image is being built:

...
#13 [base-container  9/13] COPY --chown=bentoml:bentoml . ./
#13 CACHED

#14 [base-container 10/13] RUN --mount=type=cache,target=/root/.cache/pip pip install awslambdaric==2.0.0 mangum==0.12.3
#14 0.957 Collecting awslambdaric==2.0.0
#14 0.981   Using cached awslambdaric-2.0.0.tar.gz (8.5 MB)
#14 1.070   Preparing metadata (setup.py): started
#14 1.590   Preparing metadata (setup.py): finished with status 'error'
#14 1.597   error: subprocess-exited-with-error
#14 1.597
#14 1.597   × python setup.py egg_info did not run successfully.
#14 1.597   │ exit code: 1
#14 1.597   ╰─> [15 lines of output]
#14 1.597       Error: cmake is not installed.
#14 1.597       Traceback (most recent call last):
#14 1.597         File "<string>", line 2, in <module>
#14 1.597         File "<pip-setuptools-caller>", line 34, in <module>
#14 1.597         File "/tmp/pip-install-qbghx_sn/awslambdaric_a594d95ac5944dc183af562ab4f5fcb7/setup.py", line 95, in <module>
#14 1.597           ext_modules=get_runtime_client_extension(),
#14 1.597                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#14 1.597         File "/tmp/pip-install-qbghx_sn/awslambdaric_a594d95ac5944dc183af562ab4f5fcb7/setup.py", line 46, in get_runtime_client_extension
#14 1.597           extra_link_args=get_curl_extra_linker_flags(),
#14 1.597                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#14 1.597         File "/tmp/pip-install-qbghx_sn/awslambdaric_a594d95ac5944dc183af562ab4f5fcb7/setup.py", line 19, in get_curl_extra_linker_flags
#14 1.597           check_call(["./scripts/preinstall.sh"])
#14 1.597         File "/usr/local/lib/python3.11/subprocess.py", line 413, in check_call
#14 1.597           raise CalledProcessError(retcode, cmd)
#14 1.597       subprocess.CalledProcessError: Command '['./scripts/preinstall.sh']' returned non-zero exit status 1.
#14 1.597       [end of output]
#14 1.597
#14 1.597   note: This error originates from a subprocess, and is likely not a problem with pip.
#14 1.600 error: metadata-generation-failed
#14 1.600
#14 1.600 × Encountered error while generating package metadata.
#14 1.600 ╰─> See above for output.
#14 1.600
#14 1.600 note: This is an issue with the package mentioned above, not pip.
#14 1.600 hint: See above for details.
#14 1.722 
#14 1.722 [notice] A new release of pip is available: 23.2.1 -> 23.3.1
#14 1.722 [notice] To update, run: pip install --upgrade pip
#14 ERROR: process "/bin/sh -c pip install awslambdaric==2.0.0 mangum==0.12.3" did not complete successfully: exit code: 1
------
 > [base-container 10/13] RUN --mount=type=cache,target=/root/.cache/pip pip install awslambdaric==2.0.0 mangum==0.12.3:
1.600 error: metadata-generation-failed
1.600
1.600 × Encountered error while generating package metadata.
1.600 ╰─> See above for output.
1.600
1.600 note: This is an issue with the package mentioned above, not pip.
1.600 hint: See above for details.
1.722
1.722 [notice] A new release of pip is available: 23.2.1 -> 23.3.1
1.722 [notice] To update, run: pip install --upgrade pip
------
Dockerfile:55
--------------------
  53 |     ENV BENTOML_CONFIG=/home/bentoml/bento/bentoml_config.yaml
  54 |
  55 | >>> RUN --mount=type=cache,target=/root/.cache/pip pip install awslambdaric==2.0.0 mangum==0.12.3
  56 |
  57 |     USER root
--------------------
ERROR: failed to solve: process "/bin/sh -c pip install awslambdaric==2.0.0 mangum==0.12.3" did not complete successfully: exit code: 1
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
...

Solution/Fix: Upgrading the awslambdaric version specified from the Jinja template in this repo to the latest version, currently v2.0.8, fixes the issue.
The fix can be applied locally by modifying the AWS lambda operator files at ~/bentoctl/operators/aws-lambda/bentoctl_lambda/aws_lambda/template.j2 for Linux/Mac or at %USERPROFILE%\bentoctl\operators\aws-lambda\bentoctl_lambda\aws_lambda\template.j2 for Windows.
Changing the following line:

RUN {{ common.mount_cache("/root/.cache/pip") }} pip install awslambdaric==2.0.0 mangum==0.12.3

to

RUN {{ common.mount_cache("/root/.cache/pip") }} pip install awslambdaric==2.0.8 mangum==0.12.3

fixed the issue for me. The Docker images could now build. I didn't have to switch python versions.

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

No branches or pull requests

2 participants