Bug: sam build - ImportError cannot import name 'IS_STR' from 'samtranslator.model.types'
Description:
Hi, Sam build is getting failed with an import error: cannot import name 'IS_STR' from 'samtranslator.model.types'
Error: cannot import name 'IS_STR' from 'samtranslator.model.types' (/root/.pyenv/versions/3.8.16/lib/python3.8/site-packages/samtranslator/model/types.py)
2423 | Traceback:
2424 | File "/root/.pyenv/versions/3.8.16/lib/python3.8/site-packages/click/core.py", line 1055, in main
2425 | rv = self.invoke(ctx)
2426 | File "/root/.pyenv/versions/3.8.16/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
2427 | return _process_result(sub_ctx.command.invoke(sub_ctx))
2428 | File "/root/.pyenv/versions/3.8.16/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
2429 | return ctx.invoke(self.callback, **ctx.params)
2430 | File "/root/.pyenv/versions/3.8.16/lib/python3.8/site-packages/click/core.py", line 760, in invoke
2431 | return __callback(*args, **kwargs)
2432 | File "/root/.pyenv/versions/3.8.16/lib/python3.8/site-packages/click/decorators.py", line 84, in new_func
2433 | return ctx.invoke(f, obj, *args, **kwargs)
2434 | File "/root/.pyenv/versions/3.8.16/lib/python3.8/site-packages/click/core.py", line 760, in invoke
2452 | File "/root/.pyenv/versions/3.8.16/lib/python3.8/site-packages/samcli/lib/providers/provider.py", line 17, in <module>
2453 | from samcli.lib.providers.sam_base_provider import SamBaseProvider
2454 | File "/root/.pyenv/versions/3.8.16/lib/python3.8/site-packages/samcli/lib/providers/sam_base_provider.py", line 18, in <module>
2455 | from samcli.lib.samlib.wrapper import SamTranslatorWrapper
2456 | File "/root/.pyenv/versions/3.8.16/lib/python3.8/site-packages/samcli/lib/samlib/wrapper.py", line 23, in <module>
2457 | from samtranslator.model.types import IS_STR
versions used during installation-
aws-sam-cli 1.72.0
aws-sam-translator 1.45.0
Python- 3.8
pip-23.0
setuptools-58.1.0
Could you please help me resolve this issue?
@RichaSharmaTR We don't recommend using pip for installations. If instead you move to one of our installers, this won't happen. If you still wish to use pip, you will want to isolate the installation with an venv. I would also recommend checking that return code of pip, it will report the failure that way ensure this doesn't happen again.
This happens when you first install aws-sam-cli and then install another package into the same place (python by default is global) with a different version of aws-sam-translator (we have seen this with CFN Lint). Due to how python/pip resolves dependencies, it will install all the requirements for the newest thing you pip installed. There is likely an error reported by pip that says, X package is not compatible.
To solve this, re-install aws-sam-cli
Closing as this is an issue outside of the scope of SAM CLI and is how pip tooling works.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Thankyou @jfuss