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:
aws-sam-cli using pip3 on macOSsam without argumentsObserved 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
We do not yet support Py3. Please use Py2.
Closing
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)
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.
@leepa That is the docs for develop which is ahead of all releases. We are gearing up for another release which includes Py3 support which is why the docs are updated in the develop branch but have yet to be merged to master.
We have an Issues for Py3 support already so keep this closed.
Master now says it supports 3.6 and I get this same error on 3.6.1.
I do get a slightly different error when I install without --user and just run sam:
2018-06-27 13:42:08 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 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 "/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 20, 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-06-27 13:42:08 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 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 "/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 6, in <module>
from samtranslator.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:
init Initialize a serverless application with a...
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'.
validate fails with:
: sam validate --debug
2018-06-27 13:43: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 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 "/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 6, in <module>
from samtranslator.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]...
Error: No such command "validate".
@johncblandii What does sam --version give you?
~/Work: sam --version
SAM CLI, version 0.4.
Any thoughts, @jfuss? This has become a blocker.
@johncblandii This has to do something with the version of aws-sam-translator you are using. Can you do a pip freeze and copy the version of aws-sam-translator you have installed?
1.5.4
I would expect the upgrade would address that accordingly, no?
Correction...that was pip v2.
pip3 freeze:
aws-sam-cli==0.4.0
aws-sam-translator==1.6.0
@johncblandii Does pipv2 have aws-sam-cli installed? If so, uninstall that version. My guess is that it is defaulting to the system python version you installed initially and leading to a lot of confusion.
No, pip2 is devoid of aws-sam and the translator.
Ok...weird. This combination seems to work, but I thought .4 required translator 1.6.0.
aws-sam-cli==0.4.0
aws-sam-translator==1.5.4
awscli==1.15.49
I did pip3 install --upgrade awscli just to be sure after aws-sam-translator failed to upgrade and 1.5.4 was used. Running it again output:
~/Work: pip3 install --upgrade aws-sam-translator
Collecting aws-sam-translator
Requirement not upgraded as not directly required: jsonschema~=2.6 in /Users/john.bland/Library/Python/3.6/lib/python/site-packages (from aws-sam-translator) (2.6.0)
Requirement not upgraded as not directly required: boto3~=1.5 in /Users/john.bland/Library/Python/3.6/lib/python/site-packages (from aws-sam-translator) (1.7.16)
Requirement not upgraded as not directly required: six~=1.11 in /Users/john.bland/Library/Python/3.6/lib/python/site-packages (from aws-sam-translator) (1.11.0)
Requirement not upgraded as not directly required: enum34~=1.1 in /Users/john.bland/Library/Python/3.6/lib/python/site-packages (from aws-sam-translator) (1.1.6)
Requirement not upgraded as not directly required: jmespath<1.0.0,>=0.7.1 in /Users/john.bland/Library/Python/3.6/lib/python/site-packages (from boto3~=1.5->aws-sam-translator) (0.9.3)
Requirement not upgraded as not directly required: botocore<1.11.0,>=1.10.16 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from boto3~=1.5->aws-sam-translator) (1.10.48)
Requirement not upgraded as not directly required: s3transfer<0.2.0,>=0.1.10 in /Users/john.bland/Library/Python/3.6/lib/python/site-packages (from boto3~=1.5->aws-sam-translator) (0.1.12)
Requirement not upgraded as not directly required: python-dateutil<3.0.0,>=2.1; python_version >= "2.7" in /Users/john.bland/Library/Python/3.6/lib/python/site-packages (from botocore<1.11.0,>=1.10.16->boto3~=1.5->aws-sam-translator) (2.6.1)
Requirement not upgraded as not directly required: docutils>=0.10 in /Users/john.bland/Library/Python/3.6/lib/python/site-packages (from botocore<1.11.0,>=1.10.16->boto3~=1.5->aws-sam-translator) (0.14)
aws-sam-cli 0.4.0 has requirement aws-sam-translator==1.6.0, but you'll have aws-sam-translator 1.6.1 which is incompatible.
Installing collected packages: aws-sam-translator
Found existing installation: aws-sam-translator 1.5.4
Uninstalling aws-sam-translator-1.5.4:
Successfully uninstalled aws-sam-translator-1.5.4
Successfully installed aws-sam-translator-1.6.1
pip3 freeze is now:
aws-sam-cli==0.4.0
aws-sam-translator==1.6.1
awscli==1.15.49
Now sam outputs help like it should. I'm not sure exactly what worked here or not. The freeze definitely helped me see translator existed on pip2 still, but after removing it I still received an error until the above. #weirdness
Thx @jfuss
Most helpful comment
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.