aws-sam-cli: ModuleNotFoundError: No module named 'sam_schema'

Description:

After installing the latest version of aws-sam-cli I have the following error and traceback being output into the terminal before the help text:

USS-Enterprise:~ brysontyrrell$ sam
2018-05-22 11:06:06 Command 'validate' is not configured correctly. Unable to import 'samcli.commands.validate.validate'
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samcli/cli/command.py", line 100, in get_command
    mod = importlib.import_module(pkg_name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samcli/commands/validate/validate.py", line 16, in <module>
    from .lib.sam_template_validator import SamTemplateValidator
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samcli/commands/validate/lib/sam_template_validator.py", line 5, in <module>
    from samtranslator.parser.parser import Parser
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samtranslator/parser/parser.py", line 2, in <module>
    from samtranslator.validator.validator import SamTemplateValidator
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samtranslator/validator/validator.py", line 4, in <module>
    import sam_schema
ModuleNotFoundError: No module named 'sam_schema'
2018-05-22 11:06:06 Command 'local' is not configured correctly. Unable to import 'samcli.commands.local.local'
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samcli/cli/command.py", line 100, in get_command
    mod = importlib.import_module(pkg_name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samcli/commands/local/local.py", line 8, in <module>
    from .invoke.cli import cli as invoke_cli
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samcli/commands/local/invoke/cli.py", line 11, in <module>
    from samcli.commands.local.cli_common.invoke_context import InvokeContext
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samcli/commands/local/cli_common/invoke_context.py", line 18, in <module>
    from ..lib.sam_function_provider import SamFunctionProvider
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samcli/commands/local/lib/sam_function_provider.py", line 9, in <module>
    from .sam_base_provider import SamBaseProvider
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samcli/commands/local/lib/sam_base_provider.py", line 5, in <module>
    from samcli.lib.samlib.wrapper import SamTranslatorWrapper
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samcli/lib/samlib/wrapper.py", line 18, in <module>
    from samtranslator.validator.validator import SamTemplateValidator
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/samtranslator/validator/validator.py", line 4, in <module>
    import sam_schema
ModuleNotFoundError: No module named 'sam_schema'
Usage: sam [OPTIONS] COMMAND [ARGS]...

  AWS Serverless Application Model (SAM) CLI

  The AWS Serverless Application Model extends AWS CloudFormation to provide
  a simplified way of defining the Amazon API Gateway APIs, AWS Lambda
  functions, and Amazon DynamoDB tables needed by your serverless
  application. You can find more in-depth guide about the SAM specification
  here: https://github.com/awslabs/serverless-application-model.

Options:
  --debug    Turn on debug logging
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  package  Package an AWS SAM application. This is an alias for 'aws
           cloudformation package'.
  deploy   Deploy an AWS SAM application. This is an alias for 'aws
           cloudformation deploy'.
  init     Initialize a serverless application with a...

Steps to reproduce the issue:

  1. Install aws-sam-cli using pip3 on macOS
  2. Run sam without arguments

Observed result:

Multiple ModuleNotFoundError exceptions.

Expected result:

Help text without exceptions.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

macOS 10.13.4 Python 3.6.3

Output of sam --version:

SAM CLI, version 0.3.0

Optional Debug logs:

Add --debug flag to command you are running

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

We do not yet support Py3. Please use Py2.

Closing

This should be re-opened - the docs say Py3 is supported and this error is still occurring (at least for me) on a fresh install.

For anyone that comes to this page and uses Homebrew on MacOS. I was receiving the same error thinking I was using Python 2’s pip. However, my pip commands had been mixed up. Furthermore, the sam command wasn’t in my path, but that is a general issue that can be resolved . Cheers!

bummer … I haven’t used py2 since years …

I played with this for a bit, so far the only module I can see that has problems, is the aws-sam-translator and I hacked a quick patch for it here - samtranslator.patch This makes sam local package, sam local start-api and sam local invoke work in my case (what I tested so far). It probably doesn’t fix everything, but just goes to show that there is little effort actually required to have SAM working on py3 - it mostly had only two kinds of errors - module import paths and iterating over dictionaries.

It took <15min going over everything, exception by exception, no py2to3 tool.

Python is 3.6.5, SAM is 0.3.0, OS is win10 (don’t ask … I’m stuck with it)