question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

{"errorMessage": "Unable to import module 'app'"}

See original GitHub issue

This error could be related to this issue https://github.com/awslabs/chalice/issues/105 My app.py is importing a 3rdparty module like

from chalice import Chalice
from empythy import EmpathyMachines;

that I have successfully installed via pip install --upgrade -r requirements.txt as explained in the related issue, but it seems it has not been deployed correctly by chalice on the lambda machine. My virtualenv looks like this

(env) admin@macbookproloreto:~/Developmemt/ParisiLabs/ML/tutorials/lambda-sentiment/env$ tree -d -L 4
.
β”œβ”€β”€ bin
β”œβ”€β”€ include
β”‚Β Β  └── python2.7 -> /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
└── lib
    └── python2.7
        β”œβ”€β”€ config -> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
        β”œβ”€β”€ distutils
        β”œβ”€β”€ encodings -> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings
        β”œβ”€β”€ lib-dynload -> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
        └── site-packages
            β”œβ”€β”€ empythy
            β”œβ”€β”€ empythy-0.5.6.dist-info
            β”œβ”€β”€ nltk
            β”œβ”€β”€ nltk-3.2.1.dist-info
            β”œβ”€β”€ numpy
            β”œβ”€β”€ numpy-1.11.1.dist-info
            β”œβ”€β”€ pip
            β”œβ”€β”€ pip-8.1.2.dist-info
            β”œβ”€β”€ pkg_resources
            β”œβ”€β”€ scikit_learn-0.17.1.dist-info
            β”œβ”€β”€ scipy
            β”œβ”€β”€ scipy-0.18.0.dist-info
            β”œβ”€β”€ setuptools
            β”œβ”€β”€ setuptools-25.2.0.dist-info
            β”œβ”€β”€ sklearn
            β”œβ”€β”€ wheel
            └── wheel-0.29.0.dist-info

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jameslscommented, Nov 21, 2016

As for numpy/binary file support I have a few ideas for how to making working with both C extensions as well as custom binaries easier.

I see two ways to go (maybe it’s worth doing both):

First one: Provide a hook into adding arbitrary data into the deployment zip file we send to lambda. That way as we’re adding files to the zip file we can give you a chance to inject any prebuilt binaries. I think that supporting a β€œon-build” hook would make this possible, something generic like:

#!/bin/bash
# This would be hooks/building-zip
# It would pass in several arguments:

ZIP_DIR="$1"
MY_PREBUILT_BINARIES="linux-binaries"

cp -r "$MY_PREBUILT_BINARIES/*"  "$ZIP_DIR/"

# If you wanted to, for some reason, you could also remove things from the deployed zip
rm $ZIP_DIR/unnecessary-file.py

chalice deploy would call the hooks/building-zip script if it existed.

This is probably more useful to address #42.

The second option is to try to leverage the manylinux1 wheels. I’m not exactly sure how to plumb this in, but many libraries are starting to provide manylinux wheel files (numpy, sklearn)

The latest version of pip let’s you override the platform/arch to use, so the idea would be to ask it to use manlinux wheels’s when building out the virtualenv to send to lambda. I’d have to experiment with this approach more to see if I could get it working, but the benefit of this approach would be that it would β€œjust work”, you wouldn’t have to do anything (provided your 3rd party librarys have manylinux1 wheels).

2reactions
onurmatikcommented, Nov 17, 2016

Basically the idea to make this work is to compile the required non-python extensions in the same environment as the environment that Lambda runs, which is an Amazon Linux instance, and include them in the zipped package.

I don’t know how this can be integrated into chalice but here are 2 related links: http://stackoverflow.com/questions/34749806/using-moviepy-scipy-and-numpy-in-amazon-lambda http://www.perrygeo.com/running-python-with-compiled-code-on-aws-lambda.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - "errorMessage": "Unable to import module 'app': No ...
Now I'm getting another error saying β€œunable to import module app: no module named requests” My current version of python is 3.10.2 and...
Read more >
Resolve "Unable to import module" errors from Python ... - AWS
You typically receive this error when your Lambda environment can't find the specified library in the Python code. This is because LambdaΒ ...
Read more >
Unable to import module 'lambda_function' - AWS re:Post
I get the following error when I attempt to test the lambda function. What I am I missing? { "errorMessage": "Unable to import...
Read more >
Unable to import module lambda function No ... - Edureka
Hi@akhtar,. This error appears when you haven't named your code file or function correctly. You need to go to Lambda -> Functions ->...
Read more >
Prisma cloud[ERROR] Runtime.ImportModuleError: Unable to ...
We are getting the following error in our Lambdas, [ERROR] Runtime.ImportModuleError: Unable to import module 'twistlock': Failed to import - 404799.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found