Tag: python 3.x

错误:ImportError:没有名为docx的模块 – >使用nodeJS python-shell包来控制python脚本

我正在尝试一些相对简单但是出现这个错误: Error: ImportError: No module named docx 这是我的nodeJS脚本: const python = require('python-shell'); const shell = new python('../Python/test.py'); let names = ['Hubert', 'Rupert', 'Sherbert', 'Wubbert', 'Paul']; shell.send(JSON.stringify(names)); shell.on('message', message => console.log(message)); shell.end(message => {console.log(message)}); python脚本“test.py”: import sys, json from docx import Document names = json.loads(sys.stdin.readlines()[0]) document = Document('test.docx') for name in names: for paragraph in document.paragraphs: […]

从NodeJS启动和停止Python脚本?

我如何启动和停止从一个NodeJS服务器的Python脚本? 我已经看到了模块“python-shell”,但是它并没有提供一种在运行脚本后杀死脚本的方法。

节点和python之间的通信

我有一个节点脚本: //start.js var spawn = require('child_process').spawn, py = spawn('python', ['compute_input.py']), data = [1,2,3,4,5,6,7,8,9], dataString = ''; py.stdout.on('data', function(data){ dataString += data.toString(); }); py.stdout.on('end', function(){ console.log('Sum of numbers=',dataString); }); py.stdin.write(JSON.stringify(data)); py.stdin.end(); 和一个python脚本: ## compute_input.py import sys, json, numpy as np #Read data from stdin def read_in(): lines = sys.stdin.readlines() #Since our input would only be having […]

将大的JSONstring从NodeJS发送到Python

我需要从Node发送一个大的JSON文件到Python。 我可以用spawn来创buildchild_process来调用Python文件,但是我不知道如何将数据发送给它。 我试过使用pipe道,但我不理解文档。 码: var dataset = JSON.stringify(doc.data); // Call the python API try { var py = require('child_process').spawn('python3', ['api.py', analysis, input]); } catch(error) { console.log(error); } // Pipe the data to the Python module py.stdin.pipe(fs.createWriteStream(dataset)); py.stdin.end(); 错误: Uncaught Error: ENAMETOOLONG: name too long, open [file data printed to console here]

npm使用2个版本的Python

每当我安装某些node包时,就会出现涉及Python版本的错误。 这是因为我有Python 2.7和Python 3.3 (这些是我上次更新的最新版本,但现在有3.4 ),但显然我只能在我的PATH (任何后来的文件夹被重写)源只有一个版本。 我的PATH有Python 3.3 ,因为它比较新,但是在5年之后,仍然有很多程序,包括使用Python 2 npm模块。 有什么办法可以包含一个“fallback” Python版本,对于那些不能使用版本3的模块呢? 一般的解决scheme将是惊人的,但我至less会喜欢安装npm模块的解决scheme。 请记住,有些模块对于Python 3可能是完美的,但我不确定是否有任何不能使用Python 2 。 有了这个说法,一个解决scheme,允许使用最新的版本,当兼容和一些旧版本时,不是最好的。 作为参考,我的Python 2.7安装在C:\Python27\python文件夹中, Python 3.3安装在C:\Python27\python文件夹中。 我得到的npm错误是: contextify@0.1.8安装c:\ repos \ konneka \ node_modules \ buster \ node_modules \ bus ter-syntax \ node_modules \ jsdom \ node_modules \ contextify node-gyp rebuild | c:\repos\konneka\node_modules\buster\node_modules\buster-syntax\node_modules\jsd om\node_modules\contextify>node "c:\Program Files\nodejs\node_modules\npm\bin\no de-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild […]