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.

python import issues with serverless offline

See original GitHub issue

getting this error in project with both node and python functions & serverless-offline.

Traceback (most recent call last):
  File "myproject/node_modules/serverless-offline/dist/lambda/handler-runner/python-runner/invoke.py", line 76, in <module>

    module = import_module(args.handler_path.replace(os.sep, '.'))
  File "/usr/lib64/python3.9/importlib/__init__.py", line 122, in import_module
    raise TypeError(msg.format(name))
TypeError: the 'package' argument is required to perform a relative import for '.esbuild..build.lambdas.tesseract'

I think its because the pre-offline.js modifies the path for all functions. If I manually comment out pre-offline.js (code in the conditional) - then python functions start to work, but obviously that breaks all nodejs functions.

sls invoke local works fine with both the python and node functions.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
samchungycommented, Mar 5, 2022

This is an issue actually with how serverless-offline loads python modules. https://github.com/dherault/serverless-offline/issues/993. I’ll see if I can add customisation options for where things get outputted in our repo

1reaction
samchungycommented, Mar 3, 2022

Hey @samchungy. Thanks for getting back to me. Here is a simple repo showing the issue: https://github.com/ckjoris/sls-esbuild-repro

It has two lambda functions defined, a nodejs & a python one. yarn run serverless invoke local -f func_py and yarn run serverless invoke local -f func_node work fine. However starting serverless-offline with yarn run start, then curl http://localhost:5500/func_py causes an python import issue

Thanks mate! I’m in the process of adding some integration tests so I’ll include something similar.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import local modules Error when in higher folder using ...
Summary of Issue: We are using servereless frame work with runtime python3.7 we are using the plugin servereless-python-requirements.
Read more >
Not working when using module in Python #1465 - GitHub
Bug Report Current Behavior When running sls offline and accessing the url I have the following error: Traceback (most recent call last): ...
Read more >
Python serverless: ModuleNotFoundError - Stack Overflow
To run it, I use the command $ sls offline start Then When I query on postman http://localhost:3000/dev/hello I get the error ......
Read more >
Serverless and Python: ''Unable to Import Module 'Handler'''
When writing serverless functions with Python, virtualenv users might hit a module/dependency-based error. Here's one library to get your ...
Read more >
serverless-offline-python - npm package - Snyk
An important project maintenance signal to consider for serverless-offline-python is that it hasn't seen any new versions released to npm in the ...
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