Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.89k stars 1.2k forks source link

Error: Unable to import module 'handler': No module named builtins #1262

Closed shabbirmarzban closed 6 years ago

shabbirmarzban commented 6 years ago

Context

I recently upgraded zappa to newest version (0.45.1). The module deploys well but request to gateway fail. Upon checking lambda tail I get following error Unable to import module 'handler': No module named builtins The zappa works fine if i downgrade to previous version but I want to upgrade to make use of async features(not implemented as yet. I have just upgraded the version of zappa). I also cant afford to remove slim_handler=true as mentioned here: https://github.com/Miserlou/Zappa/issues/1222 It would be great if anyone can tell the cause of this error.

Python 2.7 ## Your Environment
brunnoattorre commented 6 years ago

I had the same issue with the newest Zappa version.

ngmcfarland commented 6 years ago

I am having the same issue with version 0.45.1 as well. I am deploying from an Amazon Linux Docker image.

jeffbryner commented 6 years ago

FWIW I reverted to zappa==0.32.1 (aka the wayback machine), fought my way through pip check dependency hell and seemed to have landed at a stable platform. requirements.txt attached in case it sheds any light on things. requirements.txt

datascienceit commented 6 years ago

Same issue here with 0.45.1

titomiguelcosta commented 6 years ago

Same here, also using 0.45.1

rllin-fathom commented 6 years ago

I tried 0.32.1 but that only works with python 2 it seemed.

Using 0.43.1 seemed to move past this issue for me on python 3.6.3

iandees commented 6 years ago

I'm also getting this. I've tried deploying versions all the way back to 0.43.1 and not seeing any improvement.

iandees commented 6 years ago

I recently set up a new Zappa project using zappa==0.45.1 and it worked fine. Comparing the setup of the broken project with the new, working one, I saw that my old, broken-under-zappa-0.45.1 one was running with the python2.7 runtime setting in zappa_settings.json. Switching the broken one to use python3.6 made it work again with a recent zappa.

scoates commented 6 years ago

@iandees: is this fixed in 0.45.1, then?

aanchan commented 6 years ago

@scoates I managed to fix my issue with zappa 0.45.1. What I did after reading things in this issue:

  1. Install zappa 0.45.1 within the virtualenv. I am using Python 3.6.
  2. Do not, I repeat do not use sudo with pip install when installing stuff (zappa, sqlalchemy etc.)in the virtual env. Some of the packages get installed in the global python dist-packages.
  3. As a result on AWS the module handler.py cannot be loaded since it cannot find certain packages, e.g. builtins or werkzeug.

The error reporting on Zappa especially on the command line is super misleading since it always says "Congratulations! Your App is Live!". I'm thinking there should be some sort of environment check when packaging up the application and sending it to AWS?

jeffbryner commented 6 years ago

Oh, I love the idea of a sanity check before deploying! Sucks to find out only by testing that the deployment didn't work.

scoates commented 6 years ago

Yeah, you definitely can't sudo pip … within a virtualenv and expect it to work within the virtualenv (sudo creates a new subshell and doesn't get your pip activated path).

There's some discussion on a post-deploy sanity check here: https://github.com/Miserlou/Zappa/issues/1414

I think we can consider this issue closed. If not, please reopen. (sudo pip … is a user error, and we can't do much about it beyond checking that things deployed sanely.)

laudiacay commented 6 years ago

Y'all should seriously consider adding a check for the correct python version in the zappa init script. Mine assumed I was using python2.7, when I was using 3.6, and this led to hours of confusion because the error messages were so undescriptive!

trickidicki commented 5 years ago

I have been struggling with this issue the past couple of days. Windows, Python 3.6. Had to downgrade to Zappa==0.45.1