ImportError: cannot import name 'escape' from 'jinja2'
See original GitHub issueDescription:
During sam build we faced an issue: ImportError: cannot import name ‘escape’ from ‘jinja2’ (/usr/local/lib/python3.7/dist-packages/jinja2/init.py)
Steps to reproduce:
sam build
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: alpine
sam --version
: 1.43.0-py3-none-any- AWS region: eu-central-1
$ sam build SAM CLI now collects telemetry to better understand customer needs. You can OPT OUT and disable telemetry collection by setting the environment variable SAM_CLI_TELEMETRY=0 in your shell. Thanks for your help! Learn More: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-telemetry.html Traceback (most recent call last): File “/usr/local/bin/sam”, line 10, in <module> sys.exit(cli()) File “/usr/local/lib/python3.7/dist-packages/click/core.py”, line 829, in call return self.main(*args, **kwargs) File “/usr/local/lib/python3.7/dist-packages/click/core.py”, line 782, in main rv = self.invoke(ctx) File “/usr/local/lib/python3.7/dist-packages/click/core.py”, line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File “/usr/local/lib/python3.7/dist-packages/click/core.py”, line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File “/usr/local/lib/python3.7/dist-packages/click/core.py”, line 610, in invoke return callback(*args, **kwargs) File “/usr/local/lib/python3.7/dist-packages/click/decorators.py”, line 73, in new_func return ctx.invoke(f, obj, *args, **kwargs) File “/usr/local/lib/python3.7/dist-packages/click/core.py”, line 610, in invoke return callback(*args, **kwargs) File “/usr/local/lib/python3.7/dist-packages/samcli/lib/telemetry/metric.py”, line 166, in wrapped raise exception # pylint: disable=raising-bad-type File “/usr/local/lib/python3.7/dist-packages/samcli/lib/telemetry/metric.py”, line 124, in wrapped return_value = func(*args, **kwargs) File “/usr/local/lib/python3.7/dist-packages/samcli/lib/utils/version_checker.py”, line 41, in wrapped actual_result = func(*args, **kwargs) File “/usr/local/lib/python3.7/dist-packages/samcli/cli/main.py”, line 87, in wrapper return func(*args, **kwargs) File “/usr/local/lib/python3.7/dist-packages/samcli/commands/build/command.py”, line 192, in cli build_image, File “/usr/local/lib/python3.7/dist-packages/samcli/commands/build/command.py”, line 220, in do_cli from samcli.commands.build.build_context import BuildContext File “/usr/local/lib/python3.7/dist-packages/samcli/commands/build/build_context.py”, line 13, in <module> from samcli.lib.providers.sam_api_provider import SamApiProvider File “/usr/local/lib/python3.7/dist-packages/samcli/lib/providers/sam_api_provider.py”, line 6, in <module> from samcli.lib.providers.api_collector import ApiCollector File “/usr/local/lib/python3.7/dist-packages/samcli/lib/providers/api_collector.py”, line 10, in <module> from samcli.local.apigw.local_apigw_service import Route File “/usr/local/lib/python3.7/dist-packages/samcli/local/apigw/local_apigw_service.py”, line 11, in <module> from flask import Flask, request File “/usr/local/lib/python3.7/dist-packages/flask/init.py”, line 14, in <module> from jinja2 import escape ImportError: cannot import name ‘escape’ from ‘jinja2’ (/usr/local/lib/python3.7/dist-packages/jinja2/init.py)
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:8 (5 by maintainers)
Thanks @qingchm . Not a python expert, so there might be a better way here but manually overriding the dependency version of jinja2 works as a stop gap for us until this gets’ fixed on the sam cli side.
pip install Jinja2==2.11.3
I am having the same issue within our pipelines environment.
Docker image: image: python:3.7.4 aws sam cli - 1.43.0 aws-cli/1.22.88 Python/3.7.4 Linux/5.13.0-1017-aws botocore/1.24.33
It seems to be intermittent as if I re-run the build once or twice it works fine. I also ran the same container/commands locally with my code and did not have an issue, so I’m a little confused on what we could do to fix this. I ran into the same issue mentioned above https://github.com/pallets/flask/issues/4494 but it seems like something needs to be fixed in the sam cli build.
If it helps, this started happening a week or so ago.