Aws-sam-cli: Command 'local' is not configured correctly. Unable to import 'samcli.commands.local.local'

Created on 9 May 2018  ·  19Comments  ·  Source: aws/aws-sam-cli

Description:

After installing v0.3.0, none of the commands work anymore and there is a configuration error shown

Steps to reproduce the issue:

  1. Uninstalled npm version
  2. pip install --user aws-sam-cli
  3. sam

Observed result:

~/Work/project (master): sam
2018-05-08 17:43:58 Command 'local' is not configured correctly. Unable to import 'samcli.commands.local.local'
Traceback (most recent call last):
  File "/Users/john.bland/Library/Python/3.6/lib/python/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 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/local/local.py", line 8, in <module>
    from .invoke.cli import cli as invoke_cli
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/local/invoke/cli.py", line 11, in <module>
    from samcli.commands.local.cli_common.invoke_context import InvokeContext
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/local/cli_common/invoke_context.py", line 18, in <module>
    from ..lib.sam_function_provider import SamFunctionProvider
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/local/lib/sam_function_provider.py", line 9, in <module>
    from .sam_base_provider import SamBaseProvider
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/local/lib/sam_base_provider.py", line 5, in <module>
    from samcli.lib.samlib.wrapper import SamTranslatorWrapper
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/lib/samlib/wrapper.py", line 18, in <module>
    from samtranslator.validator.validator import SamTemplateValidator
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samtranslator/validator/validator.py", line 4, in <module>
    import sam_schema
ModuleNotFoundError: No module named 'sam_schema'
2018-05-08 17:43:58 Command 'validate' is not configured correctly. Unable to import 'samcli.commands.validate.validate'
Traceback (most recent call last):
  File "/Users/john.bland/Library/Python/3.6/lib/python/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 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/validate/validate.py", line 16, in <module>
    from .lib.sam_template_validator import SamTemplateValidator
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/validate/lib/sam_template_validator.py", line 5, in <module>
    from samtranslator.parser.parser import Parser
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samtranslator/parser/parser.py", line 2, in <module>
    from samtranslator.validator.validator import SamTemplateValidator
  File "/Users/john.bland/Library/Python/3.6/lib/python/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'.
  init     Initialize a serverless application with a...
  deploy   Deploy an AWS SAM application. This is an alias for 'aws
           cloudformation deploy'.

Expected result:

I expect the commands to work as expected. Displaying help should simply show:

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'.
  init     Initialize a serverless application with a...
  deploy   Deploy an AWS SAM application. This is an alias for 'aws
           cloudformation deploy'.

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

macOS High Sierra 10.13.2
MBP 2017
2.8 GHz Intel Core i&
16 GB of RAM

Output of sam --version:

~: sam --version
SAM CLI, version 0.3.0

Optional Debug logs:

Add --debug flag to command you are running

$ sam local invoke project --debug

2018-05-08 17:49:09 Command 'local' is not configured correctly. Unable to import 'samcli.commands.local.local'
Traceback (most recent call last):
  File "/Users/john.bland/Library/Python/3.6/lib/python/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 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/local/local.py", line 8, in <module>
    from .invoke.cli import cli as invoke_cli
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/local/invoke/cli.py", line 11, in <module>
    from samcli.commands.local.cli_common.invoke_context import InvokeContext
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/local/cli_common/invoke_context.py", line 18, in <module>
    from ..lib.sam_function_provider import SamFunctionProvider
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/local/lib/sam_function_provider.py", line 9, in <module>
    from .sam_base_provider import SamBaseProvider
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/commands/local/lib/sam_base_provider.py", line 5, in <module>
    from samcli.lib.samlib.wrapper import SamTranslatorWrapper
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samcli/lib/samlib/wrapper.py", line 18, in <module>
    from samtranslator.validator.validator import SamTemplateValidator
  File "/Users/john.bland/Library/Python/3.6/lib/python/site-packages/samtranslator/validator/validator.py", line 4, in <module>
    import sam_schema
ModuleNotFoundError: No module named 'sam_schema'
Usage: sam [OPTIONS] COMMAND [ARGS]...

Error: No such command "local".
aredistribution aretroubleshooting

Most helpful comment

Looks like this issue is back.
Getting
Command 'local' is not configured correctly. Unable to import 'samcli.commands.local.local'
with the usual trace ending .... ImportError: No module named ssl_match_hostname
pip uninstall backports.ssl-match-hostname
pip install -U docker
Did not fix, nor did updating packages, awscli aws-sam-cli & backports.ssl-match-hostname
Clearly a problem with the backports.ssl-match-hostname.
Local version is backports.ssl-match-hostname-3.5.0.1
Current work around is to change default python to 3.6 where backports.ssl-match-hostname is not needed.

All 19 comments

@johncblandii You are installing a py2 cli in py3. We don't yet support py3 due to some dependencies not being available. Please install with py2.

Closing issue. Please reopen if py2 does not work.

Dupe of #387.

You are correct, @jfuss. python is 2.7, but pip was in 3.6. I've addressed and all is well. Thx for the prompt response.

@sanathkr, not really. I'm not asking for 3.6 here. I was just trying to get it to work.

So even though my code runs in Python 3.6, I have to run sam in 2.7?

Then why does the documentation say that Python3.6 is supported too?

"Python2.7 or Python3.6"

https://github.com/awslabs/aws-sam-cli#prerequisites

@ayqazi As of now this is correct. Version 0.3.0 only supports Py2.

@kristof9851 That is the documentation of the develop branch which is ahead of all releases. Version 0.3.0 is only Py2 compatible.

I'm using sam AM CLI, version 0.5.0, Python 2.7.15 and pip 18.0 from /usr/local/lib/python2.7/site-packages/pip (python 2.7) and I'm having this problem, any ideas?

@ndelvalle Can you pip freeze and tell me what version of aws-sam-translator you have?

aws-sam-translator==1.6.0 @jfuss

@ndelvalle Are you sure you installed this in Py2? I would uninstall and see if sam is still callable. Something is funky here and not sure what it is. You shouldn't have any problems with this.

What is the output look like when the command fails?

@jfuss I ran pip uninstall aws-sam-cli and I was not able to run sam (zsh: command not found: sam) then I installed again pip install --user aws-sam-cli try to run sam local start-api and this is the result:

functions git:(master) ✗ sam local start-api
2018-08-07 19:04:25 Command 'local' is not configured correctly. Unable to import 'samcli.commands.local.local'
Traceback (most recent call last):
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/samcli/cli/command.py", line 101, in get_command
    mod = importlib.import_module(pkg_name)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/samcli/commands/local/local.py", line 8, in <module>
    from .invoke.cli import cli as invoke_cli
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/samcli/commands/local/invoke/cli.py", line 11, in <module>
    from samcli.commands.local.cli_common.invoke_context import InvokeContext
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/samcli/commands/local/cli_common/invoke_context.py", line 9, in <module>
    import docker
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/docker/__init__.py", line 2, in <module>
    from .api import APIClient
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/docker/api/__init__.py", line 2, in <module>
    from .client import APIClient
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/docker/api/client.py", line 10, in <module>
    from .build import BuildApiMixin
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/docker/api/build.py", line 6, in <module>
    from .. import auth
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/docker/auth.py", line 9, in <module>
    from .utils import config
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/docker/utils/__init__.py", line 3, in <module>
    from .decorators import check_resource, minimum_version, update_headers
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/docker/utils/decorators.py", line 4, in <module>
    from . import utils
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/docker/utils/utils.py", line 12, in <module>
    from .. import tls
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/docker/tls.py", line 5, in <module>
    from .transport import SSLAdapter
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/docker/transport/__init__.py", line 3, in <module>
    from .ssladapter import SSLAdapter
  File "/Users/ndelvalle/Library/Python/2.7/lib/python/site-packages/docker/transport/ssladapter.py", line 21, in <module>
    from backports.ssl_match_hostname import match_hostname
ImportError: No module named ssl_match_hostname
Usage: sam [OPTIONS] COMMAND [ARGS]...

Error: No such command "local".

I was able to run this in the past, not sure what update I made to break it.
PD: Thanks a lot for the help.

@ndelvalle Check out: #425

Thanks, @jfuss doing:

pip uninstall backports.ssl-match-hostname
pip install -U docker

As posted here made it work 🙌🏻

Looks like this issue is back.
Getting
Command 'local' is not configured correctly. Unable to import 'samcli.commands.local.local'
with the usual trace ending .... ImportError: No module named ssl_match_hostname
pip uninstall backports.ssl-match-hostname
pip install -U docker
Did not fix, nor did updating packages, awscli aws-sam-cli & backports.ssl-match-hostname
Clearly a problem with the backports.ssl-match-hostname.
Local version is backports.ssl-match-hostname-3.5.0.1
Current work around is to change default python to 3.6 where backports.ssl-match-hostname is not needed.

HORRIBLE user experience! It was so easy to install when it was a go lang application... There is no way I can convince my team of using this application when there is so much work around just to get it installed.

I am now receiving this error. Seems to be after I upgraded to Ubuntu 1810. Not sure if it's related?

Have the same issue since I've upgraded to Ubuntu 18.10. None of the solutions suggested in this thread have worked for me.
I worked around the problem by installing the master branch with Python 3.

Also having this issue

Thanks. To resolve above issue on Ubuntu 18.10, the second solution here worked for me..
https://stackoverflow.com/a/51071841

Refer - https://github.com/awslabs/aws-sam-cli/issues/425

Was this page helpful?
0 / 5 - 0 ratings