Skip to content

Commit 8f20c75

Browse files
committedAug 20, 2017
allow custom python binary. closes #48
1 parent 6daeb4a commit 8f20c75

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed
 

‎README.md

+11
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ custom:
9494
- .requirements-cache
9595
```
9696

97+
## Customize Python executable
98+
Sometimes your Python executable isn't available on your `$PATH` as `python2.7`
99+
or `python3.6` (for example, windows or using pyenv).
100+
To support this, this plugin has the following option:
101+
102+
```yaml
103+
custom:
104+
pythonRequirements:
105+
pythonBin: /opt/python3.6/bin/python
106+
```
107+
97108
## Manual invocations
98109

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

‎index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,22 @@ class ServerlessPythonRequirements {
8080
}
8181

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

8687
return new BbPromise((resolve, reject) => {
8788
let cmd;
8889
let options;
8990
const pipCmd = [
90-
runtime, '-m', 'pip', '--isolated', 'install',
91+
pythonBin, '-m', 'pip', '--isolated', 'install',
9192
'-t', '.requirements', '-r', '.serverless/requirements.txt',
9293
];
9394
if (this.custom().pipCmdExtraArgs) {
9495
pipCmd.push(...this.custom().pipCmdExtraArgs);
9596
}
9697
if (!this.custom().dockerizePip) {
97-
const pipTestRes = spawnSync(runtime, ['-m', 'pip', 'help', 'install']);
98+
const pipTestRes = spawnSync(pythonBin, ['-m', 'pip', 'help', 'install']);
9899
if (pipTestRes.stdout.toString().indexOf('--system') >= 0)
99100
pipCmd.push('--system');
100101
}

0 commit comments

Comments
 (0)
Failed to load comments.