serverless-python-requirements icon indicating copy to clipboard operation
serverless-python-requirements copied to clipboard

Unable to import module 'wsgi_handler': No module named 'werkzeug'

Open bibbycodes opened this issue 4 years ago • 13 comments

I keep getting this error in my AWS logs when trying to deploy using serverless:

Unable to import module 'wsgi_handler': No module named 'werkzeug'

It seems that the zip folder containing the app does not contain the right packages as specified in my requirements.txt and there is no .requirements folder either.

I have explicitly specified werkzeug in my requirements .txt and yet this package cannot be installed.

My serverless .yml:

service: serverless-flask plugins:

  • serverless-python-requirements
  • serverless-wsgi
  • serverless-dynamodb-local custom: tableName: 'transactions-table-${self:provider.stage}' wsgi: app: app.app # entrypoint is app.app, which means the app object in the app.py module. packRequirements: false pythonRequirements: dockerizePip: true dynamodb: stages:
    • test
    • dev start: migrate: true

provider: name: aws runtime: python3.6 stage: dev region: us-east-1 iamRoleStatements: - Effect: Allow Action: - dynamodb:Query - dynamodb:Scan - dynamodb:GetItem - dynamodb:PutItem Resource: - { "Fn::GetAtt": ["TransactionsDynamoDBTable", "Arn" ] } environment: TRANSACTIONS_TABLE: ${self:custom.tableName}

functions: app: handler: wsgi_handler.handler events: - http: ANY / - http: 'ANY {proxy+}' resources: Resources: TransactionsDynamoDBTable: Type: 'AWS::DynamoDB::Table' Properties: AttributeDefinitions: - AttributeName: transactionId AttributeType: S - AttributeName: timestamp AttributeType: S KeySchema: - AttributeName: transactionId KeyType: HASH - AttributeName: timestamp KeyType: RANGE ProvisionedThroughput: ReadCapacityUnits: 1 WriteCapacityUnits: 1 TableName: ${self:custom.tableName} My requrements.txt :

boto3==1.11.17 botocore==1.14.17 Click==7.0 docutils==0.15.2 Flask==1.1.1 itsdangerous==1.1.0 Jinja2==2.11.1 jmespath==0.9.4 MarkupSafe==1.1.1 python-dateutil==2.8.1 s3transfer==0.3.3 six==1.14.0 urllib3==1.25.8 Werkzeug==1.0.0 Any ideas what I'm doing wrong here?

bibbycodes avatar Feb 20 '20 14:02 bibbycodes

Been seeing this too

revmischa avatar Feb 22 '20 09:02 revmischa

same here...

adamszeptycki avatar Feb 29 '20 11:02 adamszeptycki

Same here

BenjaminWatts avatar Mar 22 '20 08:03 BenjaminWatts

The same!

4lph4-Ph4un avatar Mar 28 '20 20:03 4lph4-Ph4un

https://github.com/logandk/serverless-wsgi/issues/80

Can you guys rollback and version pin your version of serverless wsgi and make sure to be using the latest version of this plugin and try again? I suspect it is the plugin. I will do some testing of my own shortly.

AndrewFarley avatar Mar 28 '20 23:03 AndrewFarley

Mine was a false alarm, provided by not pointing to the correct requirements.txt, so all clear here even with the new version.

4lph4-Ph4un avatar Mar 30 '20 00:03 4lph4-Ph4un

did somebody find a way to fix this?

Csanchezz avatar Oct 16 '20 19:10 Csanchezz

I found this in stackoverflow and it works I downgrade Flask to 1.1.4

Flask, Werkzeug and other pallets projects just had a major update, dropping python2 support and deleting _compat module. And AWS has't resolve the capability issue yet. The simplest fix will be downgrading Flask, Werkzeug, etc. to the previous major version.

Credits to Allan Chain

eml-nx avatar May 19 '21 04:05 eml-nx

For anyone here, this is solved since version 2.0.0.

Run sls plugin install -n serverless-wsgi on your terminal inside your project folder. (At this moment, these command installs 3.0.0 version)

kevincerro avatar May 23 '22 16:05 kevincerro

(take care this message means that aws lambda does not load any packages as layer)

for mine: 1- docker installed 2- create requirements.txt 3- reduce serverless framework version from 5.x to 4.x

Output: Deploying eve-api to stage dev (us-east-1) Using Python specified in "runtime": python3.8 Packaging Python WSGI handler... Generated requirements from path/to/requirements.txt in path/to/repo/.serverless/requirements.txt... Installing requirements from path/to/repo/.serverless/requirements/requirements.txt ... Running ... Injecting required Python packages to package...

mohammad-aqajani avatar Jul 12 '22 13:07 mohammad-aqajani

Facing the same issue, anyone found a solution?

victorstefan13 avatar Nov 23 '23 17:11 victorstefan13

Could you share more context about your specific setup @victorstefan13? Are you using Flask or a similar framework? If yes, what version?

pgrzesik avatar Nov 24 '23 22:11 pgrzesik

So I managed to fix this. I think the issue was actually related to our deployment pipelines. I went down the route of pre-packing the app by creating a package directory and installing the python requirements within that directory - pip install -r requirements.txt -t package --no-deps --no-binary pydantic, copying my app to that directory and zipping the folder. Then in the serverless.yml file I specified the zipped package with artifact: package.zip. Thanks for your help!

victorstefan13 avatar Dec 06 '23 10:12 victorstefan13