New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sam init works on windows but not on mac #403

Closed
setuk opened this Issue May 10, 2018 · 13 comments

Comments

Projects
None yet
5 participants
@setuk

setuk commented May 10, 2018

Testing sam for the first time.
Installed it on Windows ok and sam init --runtime python worked fine.

Doing the same on mac yielded the following:-

sam init --runtime python
2018-05-10 17:24:49 Command 'init' is not configured correctly. Unable to import 'samcli.commands.init'
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/samcli/cli/command.py", line 100, in get_command
mod = importlib.import_module(pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/Library/Python/2.7/site-packages/samcli/commands/init/init.py", line 9, in
from samcli.local.init import generate_project
File "/Library/Python/2.7/site-packages/samcli/local/init/init.py", line 7, in
from cookiecutter.main import cookiecutter
File "/Library/Python/2.7/site-packages/cookiecutter/main.py", line 15, in
from .generate import generate_context, generate_files
File "/Library/Python/2.7/site-packages/cookiecutter/generate.py", line 27, in
from .hooks import run_hook
File "/Library/Python/2.7/site-packages/cookiecutter/hooks.py", line 13, in
from cookiecutter import utils
File "/Library/Python/2.7/site-packages/cookiecutter/utils.py", line 19, in
from .prompt import read_user_yes_no
File "/Library/Python/2.7/site-packages/cookiecutter/prompt.py", line 14, in
from past.builtins import basestring
File "/Library/Python/2.7/site-packages/past/init.py", line 88, in
from past.translation import install_hooks as autotranslate
File "/Library/Python/2.7/site-packages/past/translation/init.py", line 42, in
from lib2to3.refactor import RefactoringTool
ImportError: No module named refactor

mac install

pip install awscli
pip install aws-sam-cli

python --version
python 2.7.10

no errors

@jkeczan

This comment has been minimized.

jkeczan commented May 29, 2018

I am seeeing the same. I have verified that my Python version is 2.7 and my pip version for Python 2.7 which is the common resolution I have been seeing in other posts

@setuk

This comment has been minimized.

setuk commented May 29, 2018

This was a real pain for me when i tried to get it working it was down to a legacy version of aws-sam-cli

I had to do the following to get it working - but working now:-

1. Upgrade python
2. Uninstall awscli
3. Uninstall aws-sam-cli
4. Still had 2to3 files lying about - deleted the dir as I couldn’t pip uninstall
5. Also removed them from aws/local/site_packages
6. Reinstall awscli
7. Reinstall aws-sam-cli
@jkeczan

This comment has been minimized.

jkeczan commented May 29, 2018

where does aws/local/site_packages reside usually?

@setuk

This comment has been minimized.

setuk commented May 29, 2018

I think it was under .aws - but i deleted it and it doesnt exist there now - didn't write that part down!

@jkeczan

This comment has been minimized.

jkeczan commented May 29, 2018

Hmm..Ok, I did your steps but I am getting the same error.

My last error line is: ImportError: No module named refactor instead of the one above

@setuk

This comment has been minimized.

setuk commented May 29, 2018

That error is similar to this one
Entware/Entware-ng#268

The issue is you have python3-lib2to3 in your site packages from what i recall

@AlexOugh

This comment has been minimized.

AlexOugh commented Jun 7, 2018

I have the same problem in my mac even if I re-installed awscli & sam-cli.

Fetching lambci/lambda:python2.7 Docker container image......
2018-06-07 12:02:25 Mounting /Users/alex.ough/Projects/sam_cli/sam-app/hello_world/build as /var/task:ro inside runtime container
START RequestId: 81384622-066c-462a-a976-a29041f75caa Version: $LATEST
Unable to import module 'app': No module named app
END RequestId: 81384622-066c-462a-a976-a29041f75caa

@AlexOugh

This comment has been minimized.

AlexOugh commented Jun 7, 2018

I did a little bit of investigation and I found that the python source file (app.py) and necessary libraries (requests) are NOT deployed in 'build' folder when I run 'sam local start-api' after I created the sample project using 'sam init --runtime python'.

Should the files be deployed to 'build' folder or am I missing any commands before running 'sam local start-api' for deployment?

@setuk

This comment has been minimized.

setuk commented Jun 7, 2018

You need to create a deployment package and reference that from your SAM template. Have a look at these docs. https://docs.aws.amazon.com/lambda/latest/dg/deployment-package-v2.html

@AlexOugh

This comment has been minimized.

AlexOugh commented Jun 7, 2018

I know how to package the deployment files, but I thought this sam cli does it for you when it starts the container.

Anyway, it may be helpful to make this clear in the sam-cli documentation.

@setuk

This comment has been minimized.

setuk commented Jun 7, 2018

i just went up this learning curve so i share your pain.
I ended up with a debug build process that looks like this:-

image

Note i build my dependencies within a docker container which is Amazon Linux based else you end up with ELF header mismatch errors. Also copy all sources into the container. Output of the docker build is a zip which i reference in the SAM template.

@jfuss

This comment has been minimized.

Contributor

jfuss commented Jul 20, 2018

@AlexOugh Please follow the README that is generated from sam init --runtime python. This will explain the steps you need to take to get all your dependencies into one folder. Currently SAM CLI does not automatically do this.

As far as this issue that this was originally created for:
Python (pip in this case) installs the cli and dependencies into one global directory. This means you can only have one version of a module at one given point. By the looks of how @setuk solved this, it seems like this was the root cause. Specifically, there was some incompatible version of 2to3 installed. When pip uninstalling, pip only removes that specific module (so pip uninstall aws-sam-cli will only uninstall aws-sam-cli module and none of its dependencies). The reason goes back to the global installation Python has. PIP cannot confidently remove all dependencies because it does not know if any other module is needed by something else, so to be safe it will only remove the module requested.

This issue seems to be 'solved' but the larger story here is a better (isolated) way to install the aws-sam-cli. Doing this should avoid all of this complicated issues with Python distribution model.

@setuk I am inclined to close this since the root has been solved. We are aware of installation as a pain point and looking for ways to help relieve this but is out of the scope of this issue (imo).

@setuk

This comment has been minimized.

setuk commented Jul 20, 2018

I think its fine to close

@setuk setuk closed this Jul 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment