serverless-python-requirements: serverless deploy -> Exited with code 1

Are you certain it’s a bug?

  • Yes, it looks like a bug

Is the issue caused by a plugin?

  • It is not a plugin issue

Are you using the latest version?

  • Yes, I’m using the latest version

Is there an existing issue for this?

  • I have searched existing issues, it hasn’t been reported yet

Issue description

Error: docker run --rm -v /Users/bad_ape/Library/Caches/serverless-python-requirements/36d8e2271e2d9e8afb4b103da1d57dc91ab0ccc62422d1337b5a3a91dcc7c2d9_x86_64_slspyc:/var/task:z -v /Users/bad_ape/Library/Caches/serverless-python-requirements/downloadCacheslspyc:/var/useDownloadCache:z -u 0 lambci/lambda:build-python3.8 python3.8 -m pip install -t /var/task/ -r /var/task/requirements.txt --cache-dir /var/useDownloadCache Exited with code 1

Service configuration (serverless.yml) content

service: liqs

frameworkVersion: '2'

provider:
  name: aws
  runtime: python3.8
  lambdaHashingVersion: 20201221

functions:
  hello:
    handler: lambda_function.hello

plugins:
  - serverless-python-requirements
 
custom:
  pythonRequirements:
    dockerizePip: non-linux

Command name and used flags

serverless deploy

Command output

Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Load command interactiveCli
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command config:tabcompletion
Serverless: Load command config:tabcompletion:install
Serverless: Load command config:tabcompletion:uninstall
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command upgrade
Serverless: Load command uninstall
Serverless: Load command requirements
Serverless: Load command requirements:clean
Serverless: Load command requirements:install
Serverless: Load command requirements:cleanCache
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command generate-event
Serverless: Load command test
Serverless: Load command dashboard
Serverless: Load command output
Serverless: Load command output:get
Serverless: Load command output:list
Serverless: Load command param
Serverless: Load command param:get
Serverless: Load command param:list
Serverless: Load command studio
Serverless: Skipping variables resolution with old resolver (new resolver reported no more variables to resolve)
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Generated requirements from /Users/bad_ape/Downloads/liquidations_v2-8d3d697e-5a0a-4f55-9920-31ee9b80ac90/liqs_pipeline_1/requirements.txt in /Users/bad_ape/Downloads/liquidations_v2-8d3d697e-5a0a-4f55-9920-31ee9b80ac90/liqs_pipeline_1/.serverless/requirements.txt...
Serverless: Installing requirements from /Users/bad_ape/Library/Caches/serverless-python-requirements/36d8e2271e2d9e8afb4b103da1d57dc91ab0ccc62422d1337b5a3a91dcc7c2d9_x86_64_slspyc/requirements.txt ...
Serverless: Docker Image: lambci/lambda:build-python3.8
Serverless: Using download cache directory /Users/bad_ape/Library/Caches/serverless-python-requirements/downloadCacheslspyc
Serverless: Running docker run --rm -v /Users/bad_ape/Library/Caches/serverless-python-requirements/36d8e2271e2d9e8afb4b103da1d57dc91ab0ccc62422d1337b5a3a91dcc7c2d9_x86_64_slspyc\:/var/task\:z -v /Users/bad_ape/Library/Caches/serverless-python-requirements/downloadCacheslspyc\:/var/useDownloadCache\:z -u 0 lambci/lambda\:build-python3.8 python3.8 -m pip install -t /var/task/ -r /var/task/requirements.txt --cache-dir /var/useDownloadCache...
Serverless: [AWS sts 200 1.37s 0 retries] getCallerIdentity({})

 Error ---------------------------------------------------

  Error: `docker run --rm -v /Users/bad_ape/Library/Caches/serverless-python-requirements/36d8e2271e2d9e8afb4b103da1d57dc91ab0ccc62422d1337b5a3a91dcc7c2d9_x86_64_slspyc:/var/task:z -v /Users/bad_ape/Library/Caches/serverless-python-requirements/downloadCacheslspyc:/var/useDownloadCache:z -u 0 lambci/lambda:build-python3.8 python3.8 -m pip install -t /var/task/ -r /var/task/requirements.txt --cache-dir /var/useDownloadCache` Exited with code 1
      at ChildProcess.<anonymous> (/Users/bad_ape/Downloads/liquidations_v2-8d3d697e-5a0a-4f55-9920-31ee9b80ac90/liqs_pipeline_1/node_modules/child-process-ext/spawn.js:38:8)
      at ChildProcess.emit (node:events:390:28)
      at ChildProcess.emit (node:domain:475:12)
      at maybeClose (node:internal/child_process:1062:16)
      at Socket.<anonymous> (node:internal/child_process:448:11)
      at Socket.emit (node:events:390:28)
      at Socket.emit (node:domain:475:12)
      at Pipe.<anonymous> (node:net:687:12)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              17.2.0
     Framework Version:         2.72.0 (local)
     Plugin Version:            5.5.3
     SDK Version:               4.3.0
     Components Version:        3.18.1

Environment information

Serverless: Running "serverless" installed locally (in service node_modules)
Framework Core: 2.72.0 (local)
Plugin: 5.5.3
SDK: 4.3.0
Components: 3.18.1

MacOS Monterey 12.0.1
MB Pro 2021
Chip: Apple M1 Pro

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 16
  • Comments: 74 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I’m facing almost the same error in a Python 3.9 runtime, but with a different error code of 125 on my Mac: Error: docker run --rm -v /Users/adasgup/apps/myproject/.serverless/requirements:/var/task:z -v /Users/adasgup/Library/Caches/serverless-python-requirements/downloadCacheslspyc:/var/useDownloadCache:z -u 0 lambci/lambda:build-python3.9 python3.9 -m pip install --no-cache-dir --find-links reqs/wheels -t /var/task/ -r /var/task/requirements.txt --cache-dir /var/useDownloadCache Exited with code 125

I’m facing almost the same error in a Python 3.9 runtime, but with a different error code of 125 on my Mac: Error: docker run --rm -v /Users/adasgup/apps/myproject/.serverless/requirements:/var/task:z -v /Users/adasgup/Library/Caches/serverless-python-requirements/downloadCacheslspyc:/var/useDownloadCache:z -u 0 lambci/lambda:build-python3.9 python3.9 -m pip install --no-cache-dir --find-links reqs/wheels -t /var/task/ -r /var/task/requirements.txt --cache-dir /var/useDownloadCache Exited with code 125

I believe this is the error you get when Docker is not running?

I got the error when pip freeze > requirements.txt was written in UTF-16 encoding. Changed the encoding to UTF-8 and it’s working now.

I was on v5.4.0.
just for kicks installed npm 18.12.1 (LTS), updated serverless to latest version and tried again with same results.

you can just put any non existing package name or version in requirements.txt to get this error. for example requests==2.999 or somebadpackage==1.0.0

Error: `python3.8 -m pip install -t /home/ilya/.cache/serverless-python-requirements/4b42096495056b1a0bf6b773b4a651e3d2a33be6adbfcf82957d3e2b10db8563_x86_64_slspyc -r /home/ilya/.cache/serverless-python-requirements/4b42096495056b1a0bf6b773b4a651e3d2a33be6adbfcf82957d3e2b10db8563_x86_64_slspyc/requirements.txt --cache-dir /home/ilya/.cache/serverless-python-requirements/downloadCacheslspyc` Exited with code 1
    at ChildProcess.<anonymous> (/home/ilya/node_modules/child-process-ext/spawn.js:38:8)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess.emit (node:domain:489:12)
    at maybeClose (node:internal/child_process:1091:16)
    at Socket.<anonymous> (node:internal/child_process:449:11)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)
    at Pipe.<anonymous> (node:net:313:12)

then if you manually run the pip command from above you’ll get the actual error:

ERROR: Could not find a version that satisfies the requirement somebadpackage==1.0.0 (from versions: none)  
ERROR: No matching distribution found for somebadpackage==1.0.0  

I’m sure that if you display the pip error you’d solve a lot of headache for people

I got the same issue, would anyone guide me how to fix it?

Environment: linux, node 16.13.2, framework 3.15.2, plugin 6.2.2, SDK 4.3.2

Error: `python3.8 -m pip install -t /home/circleci/.cache/serverless-python-requirements/40acc2eb357179bb6100e638b660c2ac27ccd91e1a3af89a05c2b7ba5d4f9d76_arm64_slspyc -r /home/circleci/.cache/serverless-python-requirements/40acc2eb357179bb6100e638b660c2ac27ccd91e1a3af89a05c2b7ba5d4f9d76_arm64_slspyc/requirements.txt --cache-dir /home/circleci/.cache/serverless-python-requirements/downloadCacheslspyc` Exited with code 1
    at ChildProcess.<anonymous> (/home/circleci/repo/node_modules/child-process-ext/spawn.js:38:8)
    at ChildProcess.emit (node:events:390:28)
    at ChildProcess.emit (node:domain:475:12)
    at maybeClose (node:internal/child_process:1064:16)
    at Socket.<anonymous> (node:internal/child_process:450:11)
    at Socket.emit (node:events:390:28)
    at Socket.emit (node:domain:475:12)
    at Pipe.<anonymous> (node:net:687:12)

Exited with code exit status 1

@pgrzesik thanks for taking for taking a look at it for me.

After a few hours trying to figure it out, I found out that the problem was with the installation of serverless on my computer. I suggest for anyone who is having the same problem to check with a simple ls -la if the folder where you’re running serverless has enough permission to run. For example, in my folder I had the .serverless folder with the ownership for root, not my user. Once I changed the ownership to my user, serverless was able to run without problems

Thanks a lot @mgermy - I’ve tried to reproduce your specific issue and it seems like the problem is the python3.9 runtime. When packaging with docker, it tries to do it with lambci/lambda:build-python3.9 image that is not available - the latest available is for python3.8. I think the options here would be to

  1. Check before trying to run packaging if the runtime is supported with docker, if not error out
  2. Bring support for python3.9 runtime with docker

@patalwell Did you manage to resolve the problem on your side?

Perhaps unrelated, but I was getting the same error message as everyone else and realized that I had a package in my requirements.txt that didn’t exist in PyPi. Removing that package allowed the deployment to continue.

Just adding my experience - this was fixed after using sls package --verbose finding that there’s no 'lambci/lambda:build-python3.9' image, similar to what @isimaka has posted.

https://github.com/lambci/lambci/issues/138

I have added dockerImage: public.ecr.aws/sam/build-python3.9:latest to my config

pythonRequirements:
    dockerizePip: non-linux
    dockerImage: public.ecr.aws/sam/build-python3.9:latest
    slim: true
    layer: true

Now it is packaging without a problem

Running on windows. Noticed the requirements.txt in the cache (C:\Users\<USER>\AppData\Local\UnitedIncome\serverless-python-requirements\Cache\4672ad8e59652f4826562bf60e12f81a52440989b3b56d960144485299041ce0_x86_64_slspyc\requirements.txt) was mangled, causing errors. Appears to be an issue with copying it over to the cache.

requirements.txt before copy (in my project directory):

click==8.0.3
colorama==0.4.4
Flask==2.0.3
itsdangerous==2.0.1
Jinja2==3.0.3
MarkupSafe==2.0.1
Werkzeug==2.0.3

requirements.txt after copy in the cache:

 F l a s k = = 2 . 0 . 3 
 
 J i n j a 2 = = 3 . 0 . 3 
 
 M a r k u p S a f e = = 2 . 0 . 1 
 
 W e r k z e u g = = 2 . 0 . 3 
 c o l o r a m a = = 0 . 4 . 4 
 
 i t s d a n g e r o u s = = 2 . 0 . 1 
 
��c l i c k = = 8 . 0 . 3 

This is causing similar Exit Code 1 errors as previous people have reported.

A short-term work around is to use pipenv.

I followed the instructions on the tutorial to start and deploy a new project, and am now getting the exit code 1 error. https://www.serverless.com/blog/serverless-python-packaging/ My requirements are just: numpy==1.22.1

For the tutorial, I am running it in a Python 3.6 runtime on a Mac with Intel Core i7 processor.

I’ve also been running into the same failure as above while trying to use serverless deploy inside of a docker container

Generated requirements from /var/www/src/serverless/requirements.txt in /var/www/src/serverless/.serverless/requirements.txt
Installing requirements from "/usr/local/.cache/serverless-python-requirements/44c71bffb51a563eb8850945081619f63a4ec735828b7e8150a7400b5fda5f1f_x86_64_slspyc/requirements.txt"
Using download cache directory /usr/local/.cache/serverless-python-requirements/downloadCacheslspyc

...
× Stack xxx failed to deploy (0s)

Environment: linux, node 18.15.0, framework 3.29.0 (local) 3.29.0v (global), plugin 6.2.3, SDK 4.3.2

Error: `/usr/bin/python3.9 -m pip help install` Exited with code 1
    at ChildProcess.<anonymous> (/usr/local/node_modules/child-process-ext/spawn.js:38:8)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess.emit (node:domain:489:12)
    at maybeClose (node:internal/child_process:1091:16)
    at ChildProcess._handle.onexit (node:internal/child_process:302:5)

The python-requirements module throws this error without actually showing any pip errors. in my case I tried running the actual pip install command manually and saw that PIP returns an error for an incorrect package version. as soon as I fixed it, the error went away.

if anything, it should capture any error messages and throw them instead of “exited with code 1”

for docker, I guess you need to run “docker logs -f xxx” and see the actual pip output as well, look for errors and display them instead of just a 1 exit code.

Facing the same issue when using Python3.9 on Github Actions during CI.

Run serverless/github-action@v3.1
  with:
    args: -c "cd ./serverless && serverless package --stage dev --verbose"
    entrypoint: /bin/sh
  env:
    NODE_VERSION: 16.x
    pythonLocation: /opt/hostedtoolcache/Python/3.9.14/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.9.14/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.14/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.14/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.14/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.14/x64/lib
    AWS_DEFAULT_REGION: ***
    AWS_REGION: ***
    AWS_ACCESS_KEY_ID: ***
    AWS_SECRET_ACCESS_KEY: ***
    AWS_SESSION_TOKEN: ***
    ```
    
    ```
    Packaging app-sls for stage dev (***)

Generated requirements from /github/workspace/serverless/requirements.txt in /github/workspace/serverless/.serverless/requirements.txt
Installing requirements from "/github/workspace/serverless/.serverless/requirements/requirements.txt"
Environment: linux, node 16.17.1, framework 3.23.0 (local) 3.23.0v (global), plugin 6.2.2, SDK 4.3.2
Error:
Error: `python3.9 -m pip help install` Exited with code 1
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

    at ChildProcess.<anonymous> (/github/workspace/serverless/node_modules/child-process-ext/spawn.js:38:8)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess.emit (node:domain:489:12)
    at maybeClose (node:internal/child_process:1093:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)

1 deprecation found: run 'serverless doctor' for more details

I’m facing almost the same error in a Python 3.9 runtime, but with a different error code of 125 on my Mac: Error: docker run --rm -v /Users/adasgup/apps/myproject/.serverless/requirements:/var/task:z -v /Users/adasgup/Library/Caches/serverless-python-requirements/downloadCacheslspyc:/var/useDownloadCache:z -u 0 lambci/lambda:build-python3.9 python3.9 -m pip install --no-cache-dir --find-links reqs/wheels -t /var/task/ -r /var/task/requirements.txt --cache-dir /var/useDownloadCache Exited with code 125

I believe this is the error you get when Docker is not running?

Serverless Framework, Python, Docker, AWS Lambda, Exited with code 125

@agneeshdg @StayFoolisj

I fixed the same problem.

No, in my case, Docker is running well.

Problem locates in the docker image: lambci/lambda:build-python3.9

On this image’s docker hub, no such a tag. So Docker failed to pull the tag to local.

As @tb102122 mentioned under this issue, mlupin/docker-lambda:python3.9-build is suggested.

This worked for me.

@medikoo @pgrzesik could some more debugging be added, so more information is displayed than just error code 1 (maybe contents of stderr and stdout)? It’s possible that each of us here has a different kind of issue and we are just piling up on this error. Having more information would also allow regular users to possibly find solution themselves as it is possible that it might be someting going on a local machine. For example many of us know that error code 125 is likely docker deamon not running, but if an output would be shown that person would likely resolve it himself.

Hey, I am still struggling with this… can installing an older version of serverless-python-requirements help? This is really frustrating

Update

It turned out I was missing this, specifically for python 3.8:

ModuleNotFoundError: No module named 'distutils.cmd'

This wasn’t letting pip run so was stopping pip from doing the thing with the requirements.

So, I installed it specifically for python 3.8 - sudo apt install python3.8-distutils and then ran sls deploy with dockerizePip set to True and it still failed (don’t know why, docker 🤷), but then I set it to False so it used pip and now it works.

I’d still really appreciate a proper reason why the dockerizePip = Trrue seems to be causing issues. Thanks

I had the same issue and after running sls deploy --verbose I got this output:

ERROR: No matching distribution found for boto3==1.23.2
WARNING: You are using pip version 21.3.1; however, version 22.1 is available.
You should consider upgrading via the '/var/lang/bin/python3.9 -m pip install --upgrade pip' command.

I’m using dockerImage: mlupin/docker-lambda:python3.9-build and probably has an outdated version of pip. Using a different image with an updated pip version will probably work. Downgrading to boto3 1.23.1 is already a quickfix in this case.

I think it’s obvious that while https://github.com/serverless/serverless-python-requirements/pull/679 added extra logging, there’s still more places where logs need to be added as different people have different reasons why pip “Exited with code 1”.

I see similar issue, but when invoking python3.9 -m pip help install

00:00:09 Environment: linux, node 14.19.0, framework 3.7.8 (local), plugin 6.1.5, SDK 4.3.2
00:00:09 Credentials: Local, environment variables
00:00:09 Docs:        docs.serverless.com
00:00:09 Support:     forum.serverless.com
00:00:09 Bugs:        github.com/serverless/serverless/issues
00:00:09 
00:00:09 Error:
00:00:09 Error: `python3.9 -m pip help install` Exited with code 1
00:00:09     at ChildProcess.<anonymous> (/nix/store/gna6q42v03acmxnxqkrbvvj0krba24ry-amiman-0.1.0/node_modules/child-process-ext/spawn.js:38:8)
00:00:09     at ChildProcess.emit (events.js:400:28)
00:00:09     at ChildProcess.emit (domain.js:475:12)
00:00:09     at maybeClose (internal/child_process.js:1058:16)
00:00:09     at Process.ChildProcess._handle.onexit (internal/child_process.js:293:5)

Interestingly everything works perfectly fine when using python3.8 (yes, I cleaned cache between runs)

@reznok I believe I’m having the exact same issue as you. It seems to be an issue when generating/copying the requirements.txt. I noticed that after the step: Generated requirements from C:\Users\<USER>\Desktop\Root\requirements.txt in C:\Users\<USER>\Desktop\Root\.serverless\requirements.txt The requirements.txt in .serverless folder was also broken. Have you found a solution for this?

Update: I found this after a bit of searching:

This is an open issue as on date 10th March 2022 The serverless plugin rewrites the file into .serverless directory & it assumes UTF8 encoding when it reads the file. The problem occurs as serverless attempts to read a file with another encoding & then dump it into .serverless folder. https://github.com/serverless/serverless-python-requirements/issues/442

Instead of just showing Exited with code 1, Is there a way to see the output of the pip install command?

I did some more testing this morning and confirmed the fix I suggested was in fact not working.

The issue was that I confused the serverless error description with the command being ran, the description had the command not properly quoted, but the command being ran was properly quoted.

In my case, the cause of the error was a file not found in this setting:

dockerExtraFiles:
      - /usr/lib64/mysql/libmysqlclient.so.21

Resolving this path fixed my problem.

Tried with python 3.7 and python3.8, still same issue.

provider:
  name: aws
  runtime: python3.8 | python3.7
  
  #  lambci/lambda:build-python3.8

Defaults to container for lambda builds and runtime selected.

@vivianedias-tw no, I was just saying that, given the same serverless config and packages, it fails with serverless running under the first docker image and it works under the second one

Where did you move the issue?

Here