python-shell icon indicating copy to clipboard operation
python-shell copied to clipboard

option to specify python version

Open Almenon opened this issue 7 years ago • 2 comments

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.

Almenon avatar Mar 03 '18 04:03 Almenon

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) {

});

Drulac avatar Mar 21 '18 16:03 Drulac

I know. The point would be to do that automatically

Almenon avatar Mar 21 '18 17:03 Almenon