【发布时间】:2016-12-22 23:58:06
【问题描述】:
我一直在尝试关注 npm pythonshell here 的文档。我只是想获得一个简单的示例以正常运行,但没有成功,在线示例不多,但我确实尝试遵循此one on stackoverflow。那么我的代码到底有什么问题呢?我不确定为什么会出现以下错误。我在 python 中更舒服,nodejs 对我来说是新的领域。感谢您的帮助。
test.py 代码:
print("This is a test")
Nodejs 与 pythonshell 测试:
var PythonShell = require('python-shell');
var options = {
mode: 'text',
pythonPath: '/bin/bash/python2',
pythonOptions: ['-u'],
scriptPath: './TestProject/',
args: ['value1', 'value2', 'value3']
};
PythonShell.run('test.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
console.log('results: %j', results);
});
这是我的错误
internal/child_process.js:313
throw errnoException(err, 'spawn');
^
Error: spawn ENOTDIR
at exports._errnoException (util.js:1022:11)
at ChildProcess.spawn (internal/child_process.js:313:11)
at exports.spawn (child_process.js:387:9)
at new PythonShell (/home/nomad/TestProject/node_modules/python-shell/index.js:59:25)
at Function.PythonShell.run (/home/nomad/TestProject/node_modules/python-shell/index.js:159:19)
at Object.<anonymous> (/home/nomad/TestProject/app.js:11:13)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
【问题讨论】:
-
Error: spawn ENOTDIR表示找不到您的 python 或脚本路径。你能通过运行/bin/bash/python2来检查python 是否运行吗?另一件事,尝试scriptPath的绝对路径 -
谢谢,我最近换了disto,我的python路径是/usr/bin/python。但这不是我唯一的问题,我还需要使用绝对路径才能使脚本按您的建议运行。
标签: python node.js node-modules