Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ custom:
fileName: requirements-prod.txt
```

## Customize Python executable
Sometimes your Python executable isn't available on your `$PATH` as `python2.7`
or `python3.6` (for example, windows or using pyenv).
To support this, this plugin has the following option:
```yaml
custom:
pythonRequirements:
pythonBin: /opt/python3.6/bin/python
```

## Manual invocations

The `.requirements` and `requirements.zip`(if using zip support) files are left
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,23 @@ class ServerlessPythonRequirements {
}

const runtime = this.serverless.service.provider.runtime;
const pythonBin = this.custom().pythonBin || runtime;
this.serverless.cli.log(
`Installing required Python packages for runtime ${runtime}...`);

return new BbPromise((resolve, reject) => {
let cmd;
let options;
const pipCmd = [
runtime, '-m', 'pip', '--isolated', 'install',
pythonBin, '-m', 'pip', '--isolated', 'install',
'-t', '.requirements', '-r', fileName,
];
if (this.custom().pipCmdExtraArgs) {
pipCmd.push(...this.custom().pipCmdExtraArgs);
}
if (!this.custom().dockerizePip) {
const pipTestRes = spawnSync(runtime, ['-m', 'pip', 'help', 'install']);
const pipTestRes = spawnSync(
pythonBin, ['-m', 'pip', 'help', 'install']);
if (pipTestRes.stdout.toString().indexOf('--system') >= 0)
pipCmd.push('--system');
}
Expand Down