Getting Serverless Error spawn python3.8 ENOENT in sls deploy for python requirements

Viewed 649

Doing a serverless deployment using sls deploy and getting error "spawn python3.8 ENOENT"

ubuntu@jumpboxAndawscli:$ sudo sls deploy --stage prod
Serverless: Configuration warning at ‘provider’: unrecognized property ‘configfile’
Serverless:
Serverless: Learn more about configuration validation here:
Serverless:
Serverless: Updated deployment bucket public access block
Serverless: [serverless-package-external] is complete
Serverless: Generated requirements from /data/integrations/requirements.txt in /data/integrations/.serverless/requirements.txt…
Serverless: Installing requirements from /home/ubuntu/.cache/serverless-python-requirements/c83840509c18324c044b580033bb40d7104080235af12a1d9e3d118cf0675070_x86_64_slspyc/requirements.txt …
Serverless: Using download cache directory /home/ubuntu/.cache/serverless-python-requirements/downloadCacheslspyc

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

Error: spawn python3.8 ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
at onErrorNT (internal/child_process.js:470:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)

 For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Your Environment Information ---------------------------
Operating System: linux
Node Version: 12.22.1
Framework Version: 2.72.2
Plugin Version: 5.5.4
SDK Version: 4.3.1
Components Version: 3.18.2
3 Answers

For me, when I changed the python version from 3.8 to 3.6 in serverless.yml then only it worked.

Your local available python (current PATH) version MUST be the same version configured in your serverless.yml provider runtime value.

I had the same problem, but with python 3.9.

In my serverless.yaml file I had the runtime: python3.9 configured.
In my machine, when I ran python3 --version the result was 3.9.5.

After some time trying to understand, I finally saw that if I tried to run python3.9 --version in my machine, it didn't work.

Trying to connect the dots, I imagined that the serverless framework program needed the exact python3.9 bin name.

To solve the problem I downloaded the binaries from the Python Website, installed it and ran serverless deploy again. It worked!!!

To help you with the installation, in case you need (Ubuntu):

$ cd /opt
$ sudo wget https://www.python.org/ftp/python/3.9.13/Python-3.9.13.tgz
$ sudo tar xzf Python-3.9.13.tgz
$ cd Python-3.9.13
$ sudo ./configure --enable-optimizations
$ sudo make altinstall

There are probably other solutions for this problem like using venv or symlinks, but this one helped me first. I hope it helps you too.

Related