1

I have an nodeJS application that works perfectly on localhost, part of this NodeJS application has to run a python script which returns data using SYS. When I upload it to Heroku it fails when the python script is ran. Since I'm running the node application directly and not the python one it is difficult to get the error message directly. Instead I have put try and except messages everywhere and print messages to return to python (e.g. made it to the convert message section) and discovered it's 2 of the imports at the top of the file that is causing the python code to crash.

import sys
import spacy
import nltk

If I put the try after sys it appears that its not crashing on sys. Instead it's spacy and nltk which is causing the issues.

After some googling I found out I had to use requirements.txt to install like I would using Pip.

So in requirements.txt I have

spacy
nltk

(I tried using it with the version numbers initially but that fails)

However, this still doesn't fix the issue. I am a bit lost on how to fix this problem. Am I putting the wrong thing in requirements.txt or perhaps heroku doesnt run requirements when the nodeJS app is being ran first instead of a python file?

This is my first time using Heroku so I apologies if what I am doing wrong is obvious.

Thanks

Edit including photo of logs:

Photo of my logs,it says error R14 memory quota exceeded, I am assuming this is because JS is awaiting a reply from python which never comes

Logs when launching through terminal: part 1

part 2

Max Kenney
  • 43
  • 8
  • Please redeploy your app and copy paste the logs here when Heroku is building the environment. It contains informations about the used buildpacks, what Python version was used and which Python modules were installed. Furthermore it is possible in node.js to get `stdout` and `stderr` when executing a command line script, see: https://stackoverflow.com/questions/20643470/execute-a-command-line-binary-with-node-js Heroku logs are helpful, too. My current answer is really vague, but that's because I can't tell what the error is. Need more information. Hopefully it is just missing packages. – Tin Nguyen Mar 09 '20 at 11:54
  • @TinNguyen Hi, thank you so much for being so helpful. I tried all the steps in your reply up to buildpacks (I will need to do some reading on that now). In the meantime I have edited the post with a photo of my logs. I have been looking at heroku logs which is why I am able to tell the issue is coming from the python script. Where it says "Python Plz" is right before the python script runs and should be immediately followed by the python reply. – Max Kenney Mar 09 '20 at 15:49

1 Answers1

0

Match your development environment with your production environment (and vice versa). Make sure that the production environment (Heroku) supports your versions.

Read here about what Python versions are supported:
https://devcenter.heroku.com/articles/python-support#supported-runtimes

You can then lock that version by specifying a runtime.txt:
https://devcenter.heroku.com/articles/python-runtimes

After you made sure you are using the same Python version on both side get a copy of your installed libraries.

python3 -m pip freeze > requirements.txt

This will write all your installed Python libraries to requirements.txt. I used python3 but for you it might be called python, py or py3.

It is important to specify the Python runtime.txt because the latest Python version (3.8 and higher) does not support ntlk, see: https://pypi.org/project/nltk/

Finally explicitely specify needed Heroku buildpacks via app.json:
https://devcenter.heroku.com/articles/app-json-schema

"buildpacks": [
  {
    "url": "https://github.com/heroku/heroku-buildpack-java"
  },
  {
    "url": "https://github.com/heroku/heroku-buildpack-python"
  }
]
Tin Nguyen
  • 5,250
  • 1
  • 12
  • 32