python-shell
python-shell copied to clipboard
option to specify python version
In arepl-backend I have code that invokes "python3" instead of "python" if on a mac.
(non-windows OS ships with python 2 so python 3 needs to be specified)
It would be nice if this functionality was baked into python-shell:
var PythonShell = require('python-shell');
var options = {
version: '3',
};
var pyshell = new PythonShell('my_script.py', options);
// PythonShell uses python3 on mac, otherwise python 2
var options = {
version: '3.5',
};
pyshell = new PythonShell('my_script.py', options);
// in addition to above logic PythonShell checks the version and throws an error if wrong version
var options = {
version: '^3.5',
};
pyshell = new PythonShell('my_script.py', options);
// versioning should use [SEMVER](http://nodesource.com/blog/semver-tilde-and-caret/)
// aka 3.5 and up is allowed
var options = {
version: '^3.5',
pythonPath: 'python'
};
pyshell = new PythonShell('my_script.py', options);
// pythonPath has final decision, so even if on mac "python" will be used instead of python3
I might work on this if I have time.
You can do it just by precising python3 as python path :
var PythonShell = require('python-shell');
var options = { pythonPath: 'python3' };
PythonShell.run('my_script.py', options, function (err, results) {
});
I know. The point would be to do that automatically