gpt4 book ai didi

javascript - Meteor 如何运行服务器端 python 脚本

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:16:25 28 4
gpt4 key购买 nike

我有一个 Meteor 应用程序需要调用 python 脚本在后台执行一些操作。我怎样才能让它工作?我试过使用 child_process 和 exec,但我似乎无法让它正确执行。脚本应该放在哪里?

谢谢

最佳答案

我有同样的问题,它解决了使用 python-sheel 和 npm 包从 Node.js 运行 Python 脚本在 meteor 上安装:

meteor npm install --save python-shell

有简单的用法:

var PythonShell = require('python-shell');

PythonShell.run('my_script.py', function (err) {
if (err) throw err;
console.log('finished');
});

如果你想使用参数和选项运行:

var PythonShell = require('python-shell');

var options = {
mode: 'text',
pythonPath: 'path/to/python',
pythonOptions: ['-u'],
scriptPath: 'path/to/my/scripts',
args: ['value1', 'value2', 'value3']
};

PythonShell.run('my_script.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
console.log('results: %j', results);
});

这里有关于 python-shell 的详细信息 https://github.com/extrabacon/python-shell谢谢 extrabacon :)

关于javascript - Meteor 如何运行服务器端 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29481454/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com