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

sam init errors with "No module named functools_lru_cache"

Open fahrradflucht opened this issue 8 years ago • 20 comments

Description:

Steps to reproduce the issue:

$ sam init

Observed result:

[+] Initializing project structure...
Error: An error ocurred while generating this sam-app: Unable to load extension: No module named functools_lru_cache

Expected result: It just works!™ Additional environment details (Ex: Windows, Mac, Amazon Linux etc) macOS 10.13.5 Output of sam --version: SAM CLI, version 0.3.0 Optional Debug logs:

$ sam init --debug
2018-06-11 19:49:22 Init command
[+] Initializing project structure...
2018-06-11 19:49:22 Parameters dict created with input given
2018-06-11 19:49:22 {'no_input': False, 'output_dir': '.', 'template': '/Users/anon/Library/Python/2.7/lib/python/site-packages/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs'}
2018-06-11 19:49:22 Parameters dict updated with project name as extra_context
2018-06-11 19:49:22 {'extra_context': {'project_name': u'sam-app', 'runtime': 'nodejs8.10'}, 'no_input': True, 'output_dir': '.', 'template': '/Users/anon/Library/Python/2.7/lib/python/site-packages/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs'}
2018-06-11 19:49:22 Baking a new template with cookiecutter with all parameters
2018-06-11 19:49:22 context_file is /Users/anon/Library/Python/2.7/lib/python/site-packages/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs/cookiecutter.json
2018-06-11 19:49:22 Context generated is {u'cookiecutter': OrderedDict([(u'project_name', u'sam-app'), (u'runtime', 'nodejs8.10')])}
Error: An error ocurred while generating this sam-app: Unable to load extension: No module named functools_lru_cache

fahrradflucht avatar Jun 11 '18 17:06 fahrradflucht

Hey Mathis - That’s odd, does anything else work in Sam cli? Like generate event?

Was this Python built-in for Mac or have you installed one? Mind sharing the exact Python version?

This module actually comes from Python 3 but according to debugging you have Python 2 and we don’t actually use them in that feature either way

On Mon, 11 Jun 2018 at 18:51, Mathis Wiehl [email protected] wrote:

Description:

Steps to reproduce the issue: 1.

$ sam init --runtime go1.x

Observed result:

[+] Initializing project structure... Error: An error ocurred while generating this sam-app: Unable to load extension: No module named functools_lru_cache

Expected result: It just works!™ Additional environment details (Ex: Windows, Mac, Amazon Linux etc) macOS 10.13.5 Output of sam --version: SAM CLI, version 0.3.0 Optional Debug logs:

$ sam init --debug 2018-06-11 19:49:22 Init command [+] Initializing project structure... 2018-06-11 19:49:22 Parameters dict created with input given 2018-06-11 19:49:22 {'no_input': False, 'output_dir': '.', 'template': '/Users/anon/Library/Python/2.7/lib/python/site-packages/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs'} 2018-06-11 19:49:22 Parameters dict updated with project name as extra_context 2018-06-11 19:49:22 {'extra_context': {'project_name': u'sam-app', 'runtime': 'nodejs8.10'}, 'no_input': True, 'output_dir': '.', 'template': '/Users/anon/Library/Python/2.7/lib/python/site-packages/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs'} 2018-06-11 19:49:22 Baking a new template with cookiecutter with all parameters 2018-06-11 19:49:22 context_file is /Users/anon/Library/Python/2.7/lib/python/site-packages/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs/cookiecutter.json 2018-06-11 19:49:22 Context generated is {u'cookiecutter': OrderedDict([(u'project_name', u'sam-app'), (u'runtime', 'nodejs8.10')])} Error: An error ocurred while generating this sam-app: Unable to load extension: No module named functools_lru_cache

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/awslabs/aws-sam-cli/issues/474, or mute the thread https://github.com/notifications/unsubscribe-auth/ADL4BAet1xFct67jF5vbE2fszLcSJWtgks5t7q4agaJpZM4UjH_R .

heitorlessa avatar Jun 11 '18 19:06 heitorlessa

Hey, thanks for the quick response.

Besides init sam CLI seems to work flawlessly. I can generate events without any errors.

Python Version:

$ python --version
Python 2.7.15

Edit:

$ which python
/usr/local/bin/python
$ brew unlink python2
...
$ which python
/usr/bin/python
$ python --version
Python 2.7.10
$ sam init
[+] Initializing project structure...
Error: An error ocurred while generating this sam-app: Unable to load extension: No module named functools_lru_cache

So I think it happens on both system and installed python 2.

fahrradflucht avatar Jun 11 '18 19:06 fahrradflucht

Getting the same error. python --version Python 2.7.15

sliedig avatar Jun 19 '18 15:06 sliedig

functools_lru_cache for Py2 is apart of the backports library. I can't seem to find where this module is coming from.

We just released a Py3.6 version of the CLI (v0.4.0). Would it be possible to update and try that version (make sure you are installing with Py3.6 and not Py2.7)?

jfuss avatar Jun 19 '18 17:06 jfuss

I decided to completely reinstall the CLI with the latest version but that didn't fix it either. After installing the new version I get an additional error when I run just sam

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

sliedig avatar Jun 19 '18 21:06 sliedig

@sliedig That shouldn't happen.. hmmm... local is the first command we try importing when the cli is run.

  • What Python Version?
  • What platform are you running on?
  • Does the --debug give you any additional info?

Anything else that would allow me to repro your setup would be helpful in trying to figure out where this is coming from.

jfuss avatar Jun 20 '18 15:06 jfuss

@jfuss I have the same error: OS: OSX 10.13.5 Python: 3.6.5_1 SAM CLI: 0.4.0

➜  drissamri sam init --debug
2018-06-23 11:10:15 Init command
[+] Initializing project structure...
2018-06-23 11:10:15 Parameters dict created with input given
2018-06-23 11:10:15 {'no_input': False, 'output_dir': '.', 'template': '/Users/drissamri/Library/Python/2.7/lib/python/site-packages/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs'}
2018-06-23 11:10:15 Parameters dict updated with project name as extra_context
2018-06-23 11:10:15 {'extra_context': {'project_name': u'sam-app', 'runtime': 'nodejs8.10'}, 'no_input': True, 'output_dir': '.', 'template': '/Users/drissamri/Library/Python/2.7/lib/python/site-packages/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs'}
2018-06-23 11:10:15 Baking a new template with cookiecutter with all parameters
2018-06-23 11:10:15 context_file is /Users/drissamri/Library/Python/2.7/lib/python/site-packages/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs/cookiecutter.json
2018-06-23 11:10:15 Context generated is {u'cookiecutter': OrderedDict([(u'project_name', u'sam-app'), (u'runtime', 'nodejs8.10')])}
Error: An error ocurred while generating this sam-app: Unable to load extension: No module named functools_lru_cache

drissamri avatar Jun 23 '18 09:06 drissamri

@jfuss to answer your specific questions regarding the error

What Python Version?

~ python --version
Python 2.7.15
~ python3 --version
Python 3.6.5

What platform are you running on? OSX 10.12.6 Does the --debug give you any additional info?

~ sam init -r dotnetcore2.0
[+] Initializing project structure...
Error: An error ocurred while generating this sam-app: Unable to load extension: No module named functools_lru_cache
~ sam
2018-06-23 10:40:22 Command 'local' is not configured correctly. Unable to import 'samcli.commands.local.local'
Traceback (most recent call last):
  File "/Users/sliedig/Library/Python/2.7/lib/python/site-packages/samcli/cli/command.py", line 100, 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/sliedig/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/sliedig/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/sliedig/Library/Python/2.7/lib/python/site-packages/samcli/commands/local/cli_common/invoke_context.py", line 9, in <module>
    import docker
  File "/Users/sliedig/Library/Python/2.7/lib/python/site-packages/docker/__init__.py", line 2, in <module>
    from .api import APIClient
  File "/Users/sliedig/Library/Python/2.7/lib/python/site-packages/docker/api/__init__.py", line 2, in <module>
    from .client import APIClient
  File "/Users/sliedig/Library/Python/2.7/lib/python/site-packages/docker/api/client.py", line 10, in <module>
    from .build import BuildApiMixin
  File "/Users/sliedig/Library/Python/2.7/lib/python/site-packages/docker/api/build.py", line 6, in <module>
    from .. import auth
  File "/Users/sliedig/Library/Python/2.7/lib/python/site-packages/docker/auth.py", line 9, in <module>
    from .utils import config
  File "/Users/sliedig/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/sliedig/Library/Python/2.7/lib/python/site-packages/docker/utils/decorators.py", line 4, in <module>
    from . import utils
  File "/Users/sliedig/Library/Python/2.7/lib/python/site-packages/docker/utils/utils.py", line 12, in <module>
    from .. import tls
  File "/Users/sliedig/Library/Python/2.7/lib/python/site-packages/docker/tls.py", line 5, in <module>
    from .transport import SSLAdapter
  File "/Users/sliedig/Library/Python/2.7/lib/python/site-packages/docker/transport/__init__.py", line 3, in <module>
    from .ssladapter import SSLAdapter
  File "/Users/sliedig/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]...

  AWS Serverless Application Model (SAM) CLI

I have managed to get this to work if I create a virtual environment with pipenv using Python 3.6.5.

I'm trying to initialise a dotnetcore2.0 project, but it feels a bit weird having to create a python virtual environment to get that to work...

sliedig avatar Jun 23 '18 09:06 sliedig

I had the same problem today. Resolved be uninstalling and installing backports.functools_lru_cache.

pip uninstall backports.functools_lru_cache pip install backports.functools_lru_cache

After this everything is working again.

emilbryggare avatar Jun 27 '18 09:06 emilbryggare

Thanks @emilbryggare, I resolved in same way.

kazufumi-nishida-www avatar Jul 03 '18 08:07 kazufumi-nishida-www

@emilbryggare this solution worked. Thanks!

jdsiddon avatar Jul 03 '18 11:07 jdsiddon

The suggestion of @emilbryggare resolves it. Looks like it is an environment issue for some people. Closing it since I don't think this can be fixed at project level. (Reopen if you think otherwise.)

fahrradflucht avatar Jul 03 '18 12:07 fahrradflucht

I had the same problem today. Resolved be uninstalling and installing backports.functools_lru_cache.

pip uninstall backports.functools_lru_cache pip install backports.functools_lru_cache

After this everything is working again.

@emilbryggare Worked right for me. Thank you.

adudiapis avatar Oct 05 '18 13:10 adudiapis

nice! props @emilbryggare ! works like a dream now, thank'z again!

irishgordo avatar Nov 08 '18 19:11 irishgordo

The root cause seems that the functools_lru_cache related files were missing -

usr/lib/python2.7/dist-packages/backports$ ls
configparser  __init__.py  __init__.pyc

The above solution of uninstall/install didn't work for me. matplotlib devs on Ubuntu were having same issue. Following their discussion, fixed the missing module issue with following command -

sudo apt-get install python-matplotlib

usr/lib/python2.7/dist-packages/backports$ ls
configparser functools_lru_cache.py  functools_lru_cache.pyc  __init__.py  __init__.pyc

harprit avatar Dec 16 '18 08:12 harprit

I had the same problem today. Resolved be uninstalling and installing backports.functools_lru_cache.

pip uninstall backports.functools_lru_cache pip install backports.functools_lru_cache

After this everything is working again.

This didnt work for me. Solved the issue for myself on Fedora with the following:

dnf install python2-backports-functools_lru_cache

kepalas avatar Jan 15 '19 15:01 kepalas

Like @kepalas, the solution by @emilbryggare doesn't work for me.

In my case (Ubuntu 16.04), I had to use apt install python-backports.functools-lru-cache

kohenkatz avatar Jan 30 '19 19:01 kohenkatz

solved as per @adudiapis suggestion .

kgopi05 avatar Mar 26 '19 12:03 kgopi05

Linuxbrew and brew are our preferred ways of installing:

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-mac.html

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-linux.html

sriram-mv avatar Mar 26 '19 17:03 sriram-mv

sudo apt-get install python-matplotlib

works like charm

labohkip81 avatar Aug 22 '19 20:08 labohkip81