我正在尝试从Node.js运行一个简单的python脚本,我已经安装了python-shell
包,这是我的代码:
var PythonShell = require('python-shell');
var options = {
mode: 'text',
pythonPath: '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/',
pythonOptions: ['-u'],
scriptPath: '.',
args: ['value1', 'value2', 'value3']
};
PythonShell.run('my_script.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
console.log('results: %j', results);
});
的Python:
import sys
arg1 = sys.argv[1] #value1
arg2 = sys.argv[2] #value2
arg3 = sys.argv[3] #value3
print arg1, arg2, arg3
执行node test.js
我有这个错误:
Error: spawn EACCES
at exports._errnoException (util.js:907:11)
at ChildProcess.spawn (internal/child_process.js:298:11)
at exports.spawn (child_process.js:362:9)
at new PythonShell (/Users/Antonio/node_modules/python-shell/index.js:59:25)
at Function.PythonShell.run (/Users/Antonio/node_modules/python-shell/index.js:159:19)
at Object.<anonymous> (/Users/Antonio/Desktop/script/prova.js:11:13)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
我已使用sudo chmod -R a+rwx my_script.py
为my_script.py设置了权限。
我该如何解决这个错误?
答案 0 :(得分:0)
要解决该错误,您需要修复包含Python的Path或location的字符串。
不能像设置PATH中的PATH那样访问模块,API,库和任何其他文件。而是位于驱动器上的常规位置。 “目录映射”或位置(在搜索文件夹示例时显示,/ usr / bin / python也可以是/usr/bin/python2.7),这取决于实际.exe python文件所在的位置。 因此,请给出指示(或者缺少更好的单词Path,但不要像系统路径或任何自定义路径一样设置错误的PATH)。可执行文件的简单位置应该在字符串中,因此也不应该以/结尾。