aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Command 'local' is not configured correctly. Unable to import 'samcli.commands.local.local'

Open johncblandii opened this issue 8 years ago • 20 comments

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".

johncblandii avatar May 08 '18 22:05 johncblandii

@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.

jfuss avatar May 08 '18 23:05 jfuss

Dupe of #387.

sanathkr avatar May 08 '18 23:05 sanathkr

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.

johncblandii avatar May 09 '18 18:05 johncblandii

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

ayqazi avatar Jun 18 '18 04:06 ayqazi

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

kristof9851 avatar Jun 18 '18 11:06 kristof9851

@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.

jfuss avatar Jun 18 '18 13:06 jfuss

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 avatar Aug 07 '18 21:08 ndelvalle

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

jfuss avatar Aug 07 '18 21:08 jfuss

aws-sam-translator==1.6.0 @jfuss

ndelvalle avatar Aug 07 '18 21:08 ndelvalle

@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 avatar Aug 07 '18 22:08 jfuss

@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 avatar Aug 07 '18 22:08 ndelvalle

@ndelvalle Check out: #425

jfuss avatar Aug 07 '18 22:08 jfuss

Thanks, @jfuss doing:

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

As posted here made it work 🙌🏻

ndelvalle avatar Aug 07 '18 22:08 ndelvalle

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.

LewS avatar Oct 14 '18 01:10 LewS

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.

omar-nahhas avatar Oct 15 '18 09:10 omar-nahhas

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

mark-hayward avatar Oct 26 '18 21:10 mark-hayward

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.

Tolsto avatar Nov 05 '18 05:11 Tolsto

Also having this issue

MorelSerge avatar Dec 06 '18 16:12 MorelSerge

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

harprit avatar Dec 16 '18 08:12 harprit

Facing the same issue in mac os. Any updated on this?+

`-project/ sam 2021-02-03 10:37:01 Command 'local' is not configured correctly. Unable to import 'samcli.commands.local.local' Traceback (most recent call last): File "/Users/garciaja/apps/miniconda3/envs/noshow_aws/lib/python3.6/site-packages/samcli/cli/command.py", line 110, in get_command mod = importlib.import_module(pkg_name) File "/Users/garciaja/apps/miniconda3/envs/noshow_aws/lib/python3.6/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "/Users/garciaja/apps/miniconda3/envs/noshow_aws/lib/python3.6/site-packages/samcli/commands/local/local.py", line 8, in from .invoke.cli import cli as invoke_cli File "/Users/garciaja/apps/miniconda3/envs/noshow_aws/lib/python3.6/site-packages/samcli/commands/local/invoke/cli.py", line 9, in from samcli.commands.local.cli_common.options import invoke_common_options, local_common_options File "/Users/garciaja/apps/miniconda3/envs/noshow_aws/lib/python3.6/site-packages/samcli/commands/local/cli_common/options.py", line 9, in from samcli.commands.local.cli_common.invoke_context import ContainersInitializationMode File "/Users/garciaja/apps/miniconda3/envs/noshow_aws/lib/python3.6/site-packages/samcli/commands/local/cli_common/invoke_context.py", line 16, in from samcli.local.lambdafn.runtime import LambdaRuntime, WarmLambdaRuntime File "/Users/garciaja/apps/miniconda3/envs/noshow_aws/lib/python3.6/site-packages/samcli/local/lambdafn/runtime.py", line 13, in from samcli.lib.utils.file_observer import LambdaFunctionObserver File "/Users/garciaja/apps/miniconda3/envs/noshow_aws/lib/python3.6/site-packages/samcli/lib/utils/file_observer.py", line 16, in from watchdog.observers import Observer ModuleNotFoundError: No module named 'watchdog' 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 to print debug message generated by SAM CLI and display timestamps.

--version Show the version and exit. --info -h, --help Show this message and exit.

Commands: init Init an AWS SAM application. validate Validate an AWS SAM template. build Build your Lambda function code package Package an AWS SAM application. deploy Deploy an AWS SAM application. logs Fetch logs for a function publish Publish a packaged AWS SAM template to the AWS Serverless Application Repository. `

JaGarRod avatar Feb 03 '21 09:02 JaGarRod