簡體   English   中英

Node.js使用PythonShell運行python腳本

[英]Nodejs run python Script with PythonShell

實際上,我可以在終端中運行此python腳本並運行該腳本來創建csv文件。 但是,當我在nodejs后端運行此文件時,此文件無法創建csv文件。 我在哪里犯錯?

這是pythonshell主頁: https : //github.com/extrabacon/python-shell

var options = {
     mode: 'text',
     scriptPath: './views',
     args: [informations["camera_id"], informations.start_s, informations.start_min, informations.start_h, informations.start_d, informations.start_mon, informations.start_y, informations.end_s, informations.end_min, informations.end_h, informations.end_d, informations.end_mon, informations.end_y]
     };

var pyshell = new PythonShell('historical_inquiry_1.py', options);
     pyshell.on('message', function (message) {
     console.log("script message : ",message);
     });

這是python腳本,(測試是一個數組):

...
with open("test.csv", "w") as text_file:
        text_file.write(test)
...

實際上,我將使用它來獲取龐大的查詢結果。 正常的結果是超時。 請問我的錯,我們采取更大的mongodb查詢結果的更好方法。 提前致謝。

檢查您的nodejs工作目錄是否是包含python腳本views/historical_inquiry_1.py 我建議您在optionsscriptPath中使用絕對路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM