Я устанавливаю переменную env в node js app: process.env.data = "data-env";
Доступ к той же переменной env в моем скрипте python с помощью: print(os.environ["data"])
but getting error throw err;
^
Error: KeyError: 'data'
at PythonShell.parseError (H:\NodeJS\node_modules\python-shell\index.js:184:17)
at terminateIfNeeded (H:\NodeJS\node_modules\python-shell\index.js:98:28)
at ChildProcess.<anonymous> (H:\NodeJS\node_modules\python-shell\index.js:89:9)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
----- Python Traceback -----
File "script.py", line 5, in <module>
print(os.environ["data"])
File "C:\Program Files\Anaconda3\lib\os.py", line 725, in __getitem__
raise KeyError(key) from None
Использование приведенного ниже кода из nodeJs для запускаскрипт py
var PythonShell = require('python-shell');
var myPythonScriptPath = './script.py';
var pyshell = new PythonShell(myPythonScriptPath);
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
console.log(message);
});
// end the input stream and allow the process to exit
pyshell.end(function (err) {
if (err){
throw err;
};
console.log('finished');
});
я что-то не так делаю?