Search code examples
pythonaws-lambdapython-importpython-venvaws-serverless

Unable to import module 's_xxx': cannot import name 'formatargspec' from 'inspect' (/var/lang/lib/python3.11/inspect.py)


I just deployed my first Lambda function using the serverless framework. Since the weight of the whole project was above Lambda's limit of 250MB, I added the next section of code on serverless.yml:

package:
  exclude:
    - node_modules/**
    - venv/**

When I try any of my GET or POST methods, I get the next error:

{ "errorMessage": "Unable to import module 's_hello': cannot import name 'formatargspec' from 'inspect' (/var/lang/lib/python3.11/inspect.py)", "errorType": "Runtime.ImportModuleError", "requestId": "a5538564-75e2-4fbb-b21d-b5cb8713b061", "stackTrace": [] }

I've searched the _inspect.py file containing the 'formatargspec' function and it's in both \venv\Lib\site-packages\numpy\_utils\_inspect.py and \.serverless\requirements\numpy\_utils\_inspect.py files.

How can I fix this? If you need more information ask me and tell me how to get it if you don't mind since it's my first time interacting with Lambda and serverless. I'm using Python 3.11


Solution

  • Unfortunately, it seems like you're trying to use Serverless Dashboard integration (properietary service from Serverless, Inc.) that does not support Python 3.11 at the moment: https://github.com/serverless/dashboard-plugin/issues/711

    If you're just starting out, you might want to consider turning off that integration