Skip to content

Dependency issue: "ImportError: cannot import name 'soft_unicode' from 'markupsafe'" #688

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

Closed
rossmotley opened this issue Mar 30, 2022 · 6 comments · Fixed by #689
Closed

Comments

@rossmotley
Copy link

rossmotley commented Mar 30, 2022

I installed amaranth for the first time (version 0.3), and encountered this error:

ImportError: cannot import name 'soft_unicode' from 'markupsafe'

I found the same error which says that it's due to a change in version 2.1.0 of markupsafe.

I fixed it locally by changing to an older version with pip install markupsafe==2.0.1.

Stack trace:

...snip...
  File "/Users/rossmotley/Library/Python/3.8/lib/python/site-packages/amaranth/build/__init__.py", line 3, in <module>
    from .plat import *
  File "/Users/rossmotley/Library/Python/3.8/lib/python/site-packages/amaranth/build/plat.py", line 6, in <module>
    import jinja2
  File "/Users/rossmotley/Library/Python/3.8/lib/python/site-packages/jinja2/__init__.py", line 12, in <module>
    from .environment import Environment
  File "/Users/rossmotley/Library/Python/3.8/lib/python/site-packages/jinja2/environment.py", line 25, in <module>
    from .defaults import BLOCK_END_STRING
  File "/Users/rossmotley/Library/Python/3.8/lib/python/site-packages/jinja2/defaults.py", line 3, in <module>
    from .filters import FILTERS as DEFAULT_FILTERS  # noqa: F401
  File "/Users/rossmotley/Library/Python/3.8/lib/python/site-packages/jinja2/filters.py", line 13, in <module>
    from markupsafe import soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/Users/rossmotley/Library/Python/3.8/lib/python/site-packages/markupsafe/__init__.py)
@Lunaphied
Copy link
Contributor

Yes, I’ve encountered this recently too. Are you installing Amaranth with pip or with poetry?

@dragonmux
Copy link
Contributor

@lethalbit hit this issue yesterday and it turned out to be caused by using an out of date Jinja2 - if you're using Jinja2 versions less than 3 then you'll hit this.

@Lunaphied
Copy link
Contributor

The issue is that if you upgrade to Jinja2 3.1.0 or higher this will break Amaranth itself as the API changes made in that version rename features used in amaranth.build

@rossmotley
Copy link
Author

@modwizcode I installed via pip, and @dragonmux I got Jinja2 at version 2.11.3.

@dragonmux
Copy link
Contributor

You want Jinja2 version 3.0.3 - this will work correctly and without error

@Lunaphied
Copy link
Contributor

The correct fix is likely to fix the use of deprecated structures in Amaranth and upgrade the constraint on Jinja2 if possible. Otherwise Amaranth will have to fix a dependency on a specific version of markupsafe to avoid letting the constraint be filled with a newer incompatible version.

You hit this issue immediately with poetry because (mostly a guess) it’s constraint solver seems to try to solve for latest versions and pip seems to go for the earliest allowed versions.

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

Successfully merging a pull request may close this issue.

3 participants