3

I'm trying to use a python script with NodeJS. the code below works, but I need a way to do a 'pip install pandas' on 'npm install'

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()

1 Answer 1

3

you can use postinstall property of scripts in your package.json file to perform such operation. Here's small demo code for that.(assuming pip command will work in you cmd)

"scripts": {
 "postinstall": "pip install pandas"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.