aws-sam-cli: ImportError: cannot import name 'soft_unicode' from 'markupsafe' in Release 1.38.0
I’m building the sam project on github action and since the upgrade of sam-cli to 1.38.0, i’m getting following error when i build project
Python version: 3.10.2
& 3.8.12
(Tried both versions)
Pip version: pip-22.0.3
Sam cli version: 1.38.0
Command: sam build --template ${SAM_TEMPLATE} --use-container
Trace:
Traceback (most recent call last):
File "/home/runner/work/_temp/setup-sam-43osIE/bin/sam", line 8, in <module>
sys.exit(cli())
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 8[29](https://github.com/mensabrands/dip-app/runs/5243143255?check_suite_focus=true#step:5:29), in __call__
return self.main(*args, **kwargs)
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/lib/telemetry/metric.py", line 166, in wrapped
raise exception # pylint: disable=raising-bad-type
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/lib/telemetry/metric.py", line 124, in wrapped
return_value = func(*args, **kwargs)
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/lib/utils/version_checker.py", line 41, in wrapped
actual_result = func(*args, **kwargs)
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/cli/main.py", line 87, in wrapper
return func(*args, **kwargs)
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/commands/build/command.py", line 174, in cli
do_cli(
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/commands/build/command.py", line 220, in do_cli
from samcli.commands.build.build_context import BuildContext
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/commands/build/build_context.py", line 13, in <module>
from samcli.lib.providers.sam_api_provider import SamApiProvider
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/lib/providers/sam_api_provider.py", line 6, in <module>
from samcli.lib.providers.api_collector import ApiCollector
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/lib/providers/api_collector.py", line 10, in <module>
from samcli.local.apigw.local_apigw_service import Route
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/samcli/local/apigw/local_apigw_service.py", line 11, in <module>
from flask import Flask, request
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/flask/__init__.py", line 14, in <module>
from jinja2 import escape
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/jinja2/__init__.py", line 12, in <module>
from .environment import Environment
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/jinja2/environment.py", line 25, in <module>
from .defaults import BLOCK_END_STRING
File "/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/jinja2/defaults.py", line 3, in <module>
from .filters import FILTERS as DEFAULT_FILTERS # noqa: F[40](https://github.com/mensabrands/dip-app/runs/5243143255?check_suite_focus=true#step:5:40)1
File "/home/runner/work/_temp/setup-sam-[43](https://github.com/mensabrands/dip-app/runs/5243143255?check_suite_focus=true#step:5:43)osIE/.venv/lib/python3.10/site-packages/jinja2/filters.py", line 13, in <module>
from markupsafe import soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/home/runner/work/_temp/setup-sam-43osIE/.venv/lib/python3.10/site-packages/markupsafe/__init__.py)
I revert sam-cli version to 1.37.0
and it worked perfectly.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 67
- Comments: 44 (2 by maintainers)
Links to this issue
Commits related to this issue
- fix for https://github.com/aws/aws-sam-cli/issues/3661 — committed to nuvla/kafka-notify by konstan 2 years ago
- Merge pull request #13 from nuvla/fix-12 * fix issue * test and build in CI * minor * typo * fix for https://github.com/aws/aws-sam-cli/issues/3661 * exec permission for container-release.sh * ... — committed to nuvla/kafka-notify by konstan 2 years ago
- Merge pull request #100 from SORTEE-Github-Hackathon/RCO-fixes-brackets Update 05.use-cases-c.md — committed to SORTEE-Github-Hackathon/manuscript by emmajhudgins 2 years ago
- Fix markupsafe bug - see https://github.com/aws/aws-sam-cli/issues/3661 — committed to mtruj013/ubuntu.com by nottrobin 2 years ago
- [build] fix build exception and revert #9136 (#10037) #### Why I did it 1. Fix Build exception [example](https://dev.azure.com/mssonic/build/_build/results?buildId=73911&view=logs&jobId=88ce9a53-7... — committed to sonic-net/sonic-buildimage by ghooo 2 years ago
- [SPARK-38279][TESTS][3.2] Pin MarkupSafe to 2.0.1 fix linter failure ### What changes were proposed in this pull request? This PR proposes to pin the Python package `markupsafe` to 2.0.1 to fix the ... — committed to apache/spark by itholic 2 years ago
- [SPARK-38279][TESTS][3.2] Pin MarkupSafe to 2.0.1 fix linter failure This PR proposes to pin the Python package `markupsafe` to 2.0.1 to fix the CI failure as below. ``` ImportError: cannot import n... — committed to apache/spark by itholic 2 years ago
- [SPARK-38279][TESTS][3.2] Pin MarkupSafe to 2.0.1 fix linter failure This PR proposes to pin the Python package `markupsafe` to 2.0.1 to fix the CI failure as below. ``` ImportError: cannot import n... — committed to apache/spark by itholic 2 years ago
- [SPARK-38279][TESTS][3.2] Pin MarkupSafe to 2.0.1 fix linter failure This PR proposes to pin the Python package `markupsafe` to 2.0.1 to fix the CI failure as below. ``` ImportError: cannot import n... — committed to apache/spark by itholic 2 years ago
- fix: https://github.com/aws/aws-sam-cli/issues/3661 — committed to aliyun/algorithm-base by cactusgame 2 years ago
- add specific version of markupsafe Due to breaking changes (https://github.com/aws/aws-sam-cli/issues/3661) — committed to prefeitura-rio/queries-datario by gabriel-milan 2 years ago
- CIDC-1278 add markupsafe version to fix CI see https://github.com/aws/aws-sam-cli/issues/3661 — committed to CIMAC-CIDC/cidc-schemas by scvannost 2 years ago
- Bump markupsafe 2.1.0 to 2.0.1 When licode docker build, there is some error with markupsafe version. markupsafe installed automatically this logic. so i added pip install. ref : https://github.c... — committed to nowjean/licode by nowjean 2 years ago
- dockerfile: Upgrade alpine and remove jinja workaround 1) Simply apply minor upgrade on alpine image version. 2) Remove pinning on Jinja, the upstream bug is now fixed. Also the pinned version of J... — committed to cycloidio/docker-cycloid-toolkit by gaelL 2 years ago
- Fix for jinja2/markupsafe issue with CI https://github.com/aws/aws-sam-cli/issues/3661 — committed to emirkmo/flows by emirkmo 2 years ago
- Pipfile Updates Changes: 1. insights-core source(PyPi) 2. markupsafe explicit downgrade to 2.0.1 Reasons: 1. git has over 70 dependencies, these end up in teh final app image 2. markupsafe's late... — committed to saltgen/ros-backend by deleted user 2 years ago
- Pin MarkupSafe to fix docs building The Python package MarkupSafe has a breaking change in version 2.1.0 that makes it incompatible with many currently-released packages. See https://github.com/aws/... — committed to babycat-io/babycat by jamesmishra 2 years ago
- Pin MarkupSafe to fix docs building (#53) The Python package MarkupSafe has a breaking change in version 2.1.0 that makes it incompatible with many currently-released packages. See https://githu... — committed to babycat-io/babycat by jamesmishra 2 years ago
- RHIROS-471 | Pipfile Updates (#196) * Pipfile Updates Changes: 1. insights-core source(PyPi) 2. markupsafe explicit downgrade to 2.0.1 Reasons: 1. git has over 70 dependencies, these en... — committed to RedHatInsights/ros-backend by saltgen 2 years ago
Downgrading markupsafe to 2.0.1 fixes the issue on my side.
pip install markupsafe==2.0.1
Looks the issue is due to upgrade in
MarkupSafe:2.1.0
where they have removedsoft_unicode
. Release note: https://markupsafe.palletsprojects.com/en/2.1.x/changes/#version-2-1-0sam-cli:1.37.0
is downloadingMarkupSafe:2.0.1
andsam-cli:1.38.0
is downloadingMarkupSafe:2.1.0
.@sthadapradit this I did, but it is temproary solution - any idea how to come back to pip install --user --upgrade aws-sam-cli insted pip install --user aws-sam-cli ==1.37.0
same here - seems MarkUoSafe was updated and there is no soft_unicode there any more. How to solve this?
pip install --user --upgrade aws-sam-cli - gets last version on Jijnja
Collecting Jinja2<4.0.0,>=2.7 Using cached Jinja2-3.0.3-py3-none-any.whl (133 kB)
yesterday was Collecting Jinja2<4.0.0,>=2.7 Using cached Jinja2-2.11.3-py2.py3-none-any.whl (125 kB)
aws-sam-cli is using an unsupported version of Jinja, they need to update to the latest version. Additionally, they need to read https://hynek.me/articles/semver-will-not-save-you/, then use a tool like pip-tools to pin their dependencies to control when their users get updates. Be sure to run tests with deprecation warnings treated as errors so that these types of changes show up early.
Thanks a lot. It solved the problem
Looking into this. Though this is why we do not recommend using pip to install and instead use our installers.
@davidism We are stuck in a place that if we pin, customers get upset that they can install with all their other tools (in a single interpreter instead of isolating). If we don’t pin (everything), we run into this things. So it’s a who do we block/make angry situation. Would be great if python (pip) actually solved this instead of each tool having to battle users on how to install or providing ways tools can vend safely through pip.
@SamkeetJainMensa, thanks lot, it’s working with 1.37.0, I did this change in gitaction
I had this issue with Django using Jinja2. Jinja2 imports
soft_unicode
from the package causing it to break.This Issue can be solve using below for steps:
For anyone finding this organically through search, you might have been searching up the following error:
I’m not using aws-sam-cli, but I believe one of my dependencies is using jinja (which uses MarkupSafe). I added an upper bound to the MarkupSafe dependency at the top of my requirements.txt file (if that’s something you’re using).
My GitHub Actions workflow uses the requirements file to setup testing, so this made life a bit easier. I imagine @Yop-La’s solution (https://github.com/aws/aws-sam-cli/issues/3661#issuecomment-1044340547) would work just as well.
How I solved it is after all the project dependencies are installed, I do a 'pip uninstall -y markupsafe ’ and then a 'pip install markupsafe==2.0.1 '. Hope this helps someone.
Like mentioned above in https://github.com/aws/aws-sam-cli/issues/3661#issuecomment-1044340547, you can “pin” it by adding the version number explicitly (
markupsafe==2.0.1
) in your pip install:pip install markupsafe==2.0.1
It works the same when you’re installing something else:
pip install something_that_depends_on_markupsafe_transitively markupsafe==2.0.1
See: https://stackoverflow.com/questions/44448925/how-to-pin-transitive-dependencies-with-setup-py-in-python
Why has this been closed? 🤔 This is still an issue with version
1.38.1.
because ofFlask
’s dependency.Thanks for reporting this issue. SAM CLI v1.38.1 is released which contains the fix for it. As @jfuss mentioned, we would highly recommend using our installers (NativeInstaller for Linux, brew for MacOS and MSI for Windows).
Resolving the issue.
Just ran into this issue installing with
aws-actions/setup-sam@v1
easy fix if anyone else sees this though, setup-sam allows you to set version
To be honest, there is no perfect solution, because it depends on your environmental configuration.
What is the error on your machine ?