python - 为什么我在 node.js 中调用 python-shell 时出现 TypeError?
问题描述
我正在尝试在 node.js 中运行 Python 程序,我的代码:
import {PythonShell} from 'python-shell';
var pyshell = PythonShell.run('./myscript.py', options,
function(err:any, results:any)
{
if (err) throw err;
else console.log(results);
});
pyshell.on('message', function (message: any) {
// received a message sent from the Python script (a simple "print" statement)
console.log(message);
});
// end the input stream and allow the process to exit
pyshell.end(function (err: any) {
if (err){
throw err;
};
console.log('finished');
});
但我得到了错误:
TypeError: The "original" argument must be of type Function promisify .../node_modules/util/util.js:601
所以我想这可能与 PythonShell 的定义方式有关,即不是函数而是对象。但不知道如何修复它。我也试过:
const {PythonShell} = require('python-shell');
解决方案
推荐阅读
- amazon-web-services - Redshift 查询限制为 100 mb
- docker - 添加日志记录选项时,Docker Compose 不起作用
- javascript - TypeError:无法使用 TypeDi 读取未定义的属性“authService”
- floating-point - 具有替代测量单位的定点/整数表示的名称
- python - 如何修复:“HadoopFileSystem 加载错误:libhdfs.so:无法打开共享对象文件:没有这样的文件或目录 10:49:33 Traceback”?
- report - 如何生成排毒测试报告?
- javascript - parse date-fns 返回前一天的值
- flutter - 在 Flutter v2.5 中迁移强调色
- reactjs - 错误 - unhandledRejection:错误:Object.react-markdown 不支持
- selenium - 在 Windows 服务器上运行 selenium 自动化测试时存在验证码