javascript上でpython-shellを使ってpythonを呼びだそうとしています。
コードは公式(?)のサイトから参考にしています。
python-shell - npm
javascript
1let { PythonShell } = require('python-shell'); 2 3let options = { 4 mode: 'text', 5 pythonPath: '/usr/lib/python3.5', 6 pythonOptions: ['-u'], // get print results in real-time 7 scriptPath: '/home/M1/web/test.py', 8 args: [envelope.latitude, envelope.longitude, envelope.spot] 9}; 10 11PythonShell.run('test.py', options, function (err, results) { 12 if (err) throw err; 13 // results is an array consisting of messages collected during execution 14 console.log('results: %j', results); 15});
実行したところ以下のようなエラーが出ました。
/home/M1/web/node_modules/python-shell/index.js:99 self.parser && self[name].setEncoding(options.encoding || 'utf8'); ^ TypeError: Cannot read property 'setEncoding' of undefined at /home/M1/web/node_modules/python-shell/index.js:99:39 at Array.forEach (<anonymous>) at new PythonShell (/home/M1/web/node_modules/python-shell/index.js:97:39) at Function.run (/home/M1/web/node_modules/python-shell/index.js:197:23) at WebSocket.client.on (/home//M1/web/get_latlon.js:49:21) at WebSocket.emit (events.js:198:13) at Receiver.receiverOnMessage (/home/M1/web/node_modules/ws/lib/websocket.js:720:20) at Receiver.emit (events.js:198:13) at Receiver.dataMessage (/home/M1/web/node_modules/ws/lib/receiver.js:414:14) at Receiver.getData (/home/M1/web/node_modules/ws/lib/receiver.js:346:17)
そもそも let option の設定がいまいちわかっておらず
いろんなサイトを見たり、友達に聞きながら設定したのですが、
scriptPath とは呼び出すpythonのファイルの場所を指定すればよかったのでしょうか?
また、argsの書き方もあってるか不安です。。。
エラーの意味や解決策など教えていただければ嬉しいです。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/03 05:50 編集
2019/07/03 07:50 編集
2019/07/03 08:16