【发布时间】:2019-09-10 17:06:00
【问题描述】:
我在树莓派 4 上有以下项目: 我在 python 中创建了一个需要虚拟环境才能运行的人脸识别脚本。 脚本打印出被检测到的人。
在 NodeJS 中,我想通过在节点中运行脚本来获得答案(缩小版):
const http = require("http");
const server = http.createServer((req, res) => {
var spawn = require('child_process').spawn,
py = spawn('python', ['faceReg.py'],)
py.stdout.on('data', function(data){
console.log('Data:' + data);
});
py.stdout.on('end', function(){
console.log('Python ended');
});
});
执行代码时,我立即得到“python 结束”。
在我的 pi 上,当我在执行前运行以下命令时,我可以运行脚本:
source ~/.virtualenvs/cv2_env/bin/activate
python脚本基本是:
stop = False
while(stop==False):
print("Peter")
更新
运行时
py = spawn('~/.virtualenvs/cv2_env/bin/python', ['faceReg.py'])
我收到以下错误:
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn ~/.virtualenvs/cv2_env/bin/python ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
[... lines matching original stack trace ...]
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
我做错了什么?
【问题讨论】:
标签: python node.js raspberry-pi virtual-environment