Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js python脚本中的熊猫可以与NodeJ一起使用吗_Node.js_Python 3.x_Pandas - Fatal编程技术网

Node.js python脚本中的熊猫可以与NodeJ一起使用吗

Node.js python脚本中的熊猫可以与NodeJ一起使用吗,node.js,python-3.x,pandas,Node.js,Python 3.x,Pandas,我正在尝试调用一个带有NodeJS的python脚本,它将与python“helloworld”脚本一起工作,但是当脚本使用pandas时,我无法让python脚本执行 numpy==1.15.1 熊猫==0.23.4 nodeJS router.get('/', (req, res) => { const filePath = 'python/testing2.py' const spawn = require("child_process").spawn; const p

我正在尝试调用一个带有NodeJS的python脚本,它将与python“helloworld”脚本一起工作,但是当脚本使用pandas时,我无法让python脚本执行

numpy==1.15.1 熊猫==0.23.4

nodeJS

router.get('/', (req, res) => {
  const filePath = 'python/testing2.py' 
  const spawn = require("child_process").spawn;
  const pythonProcess = spawn('python3',[filePath, '-l']); 

  util.log('readingin')
  pythonProcess.stdout.on('data', (data) => { 
    const textChunk = data.toString('utf8');// buffer to string
    util.log(textChunk);
    res.json({'working': true, 'data': textChunk})
  });
});
python:

import sys 
from pandas import read_csv
from pandas import datetime    

def parser(x):
    return datetime.strptime('190'+x, '%Y-%m')    

print("Output from Python") 
series = read_csv('shampoo-sales.csv', header=0, parse_dates=[0], index_col=0, squeeze=True, date_parser=parser)
print (series)
sys.stdout.flush()
如果我自己运行python脚本:

$ python3 testing2.py
Output from Python
Month
1901-01-01    266.0
1901-02-01    145.9
1901-03-01    183.1
1901-04-01    119.3...

$ pip3 freeze
matplotlib==2.2.3
numpy==1.15.1
pandas==0.23.4

始终检查从其他进程运行的命令是否使用与预期相同的Python可执行文件。常见的方法有

which python3

从你的壳里,或者

import sys
print(sys.executable)

在您的Python脚本中。

在我的例子中,我使用PythonShell运行方法,使用PythonShell npm包:

您需要为Python Shell提供将pythonPath指向virtualenv中路径的选项:

  var options = {
    mode: 'text',
    pythonPath: '/Users/WC/anaconda/envs/testtoday/bin/python',
    pythonOptions: ['-u'], // get print results in real-time
    scriptPath: '/Volumes/Transcend/NodeJSTest/PythonNodeJS',
    args:
    [
      req.query.funds, // starting funds
      req.query.size, // (initial) wager size
      req.query.count, // wager count - number of wagers per sim
      req.query.sims // number of simulations
    ]
  }

  ps.PythonShell.run('./d_alembert.py', options, function (err, data) {
    if (err) res.send(err);
    res.send(data.toString());
  });
要查找virtualenv的路径,请激活它:

source activate testtoday
然后输入:

which python

virtualenv中的所有导入都可以在脚本中使用。

pandas是为
python3
安装的吗?是的,它对您有用吗?您确定节点查找的
python3
与bash查找的
python3
相同吗?如果生成的是哪个python3,那么输出是什么?或者将您的脚本更改为仅导入sys print(sys.executable)?谢谢,我使用的是/usr/local/bin/python3,而不是我的venv中的脚本
which python