Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 0cd8a05

Browse files
authored
Merge pull request #60 from UnitedIncome/custom-python-bin
allow custom python binary. closes #48
2 parents 891c065 + 7e08333 commit 0cd8a05

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ custom:
108108
fileName: requirements-prod.txt
109109
```
110110

111+
## Customize Python executable
112+
Sometimes your Python executable isn't available on your `$PATH` as `python2.7`
113+
or `python3.6` (for example, windows or using pyenv).
114+
To support this, this plugin has the following option:
115+
```yaml
116+
custom:
117+
pythonRequirements:
118+
pythonBin: /opt/python3.6/bin/python
119+
```
120+
111121
## Manual invocations
112122

113123
The `.requirements` and `requirements.zip`(if using zip support) files are left

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,23 @@ class ServerlessPythonRequirements {
5353
}
5454

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

5960
return new BbPromise((resolve, reject) => {
6061
let cmd;
6162
let options;
6263
const pipCmd = [
63-
runtime, '-m', 'pip', '--isolated', 'install',
64+
pythonBin, '-m', 'pip', '--isolated', 'install',
6465
'-t', '.requirements', '-r', fileName,
6566
];
6667
if (this.custom().pipCmdExtraArgs) {
6768
pipCmd.push(...this.custom().pipCmdExtraArgs);
6869
}
6970
if (!this.custom().dockerizePip) {
70-
const pipTestRes = spawnSync(runtime, ['-m', 'pip', 'help', 'install']);
71+
const pipTestRes = spawnSync(
72+
pythonBin, ['-m', 'pip', 'help', 'install']);
7173
if (pipTestRes.stdout.toString().indexOf('--system') >= 0)
7274
pipCmd.push('--system');
7375
}

0 commit comments

Comments
 (0)