简体   繁体   English

从 python 脚本获取数据时,运行在 Heroku 上的 NodeJS 应用程序失败

[英]NodeJS application running on Heroku fails when getting data from a python script

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.我有一个在本地主机上完美运行的 nodeJS 应用程序,这个 NodeJS 应用程序的一部分必须运行一个 python 脚本,该脚本使用 SYS 返回数据。 When I upload it to Heroku it fails when the python script is ran.当我将它上传到 Heroku 时,它会在运行 python 脚本时失败。 Since I'm running the node application directly and not the python one it is difficult to get the error message directly.由于我直接运行节点应用程序而不是 python 应用程序,因此很难直接获取错误消息。 Instead I have put try and except messages everywhere and print messages to return to python (eg 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.相反,我已将 try 和 except 消息放在任何地方,并打印消息以返回到 python(例如,将其发送到转换消息部分)并发现它是导致 python 代码崩溃的文件顶部的 2 个导入。

import sys
import spacy
import nltk

If I put the try after sys it appears that its not crashing on sys.如果我将 try 放在 sys 之后,它似乎不会在 sys.path 上崩溃。 Instead it's spacy and nltk which is causing the issues.相反,导致问题的是 spacy 和 nltk。

After some googling I found out I had to use requirements.txt to install like I would using Pip.经过一番谷歌搜索后,我发现我必须像使用 Pip 一样使用 requirements.txt 进行安装。

So in requirements.txt I have所以在requirements.txt我有

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?我是否在 requirements.txt 中放了错误的东西,或者当首先运行 nodeJS 应用程序而不是 python 文件时,heroku 没有运行需求?

This is my first time using Heroku so I apologies if what I am doing wrong is obvious.这是我第一次使用 Heroku,所以如果我做错了什么很明显,我深表歉意。

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我的日志照片,它说错误 R14 内存配额超出,我假设这是因为 JS 正在等待来自 python 的回复,但永远不会出现

通过终端启动时的日志:第 1 部分

第2部分

Match your development environment with your production environment (and vice versa).使您的开发环境与生产环境相匹配(反之亦然)。 Make sure that the production environment (Heroku) supports your versions.确保生产环境 (Heroku) 支持您的版本。

Read here about what Python versions are supported:在此处阅读有关支持哪些 Python 版本的信息:
https://devcenter.heroku.com/articles/python-support#supported-runtimes https://devcenter.heroku.com/articles/python-support#supported-runtimes

You can then lock that version by specifying a runtime.txt :然后,您可以通过指定runtime.txt来锁定该版本:
https://devcenter.heroku.com/articles/python-runtimes 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.在确保双方使用相同的 Python 版本后,获取已安装库的副本。

python3 -m pip freeze > requirements.txt

This will write all your installed Python libraries to requirements.txt .这会将您安装的所有 Python 库写入requirements.txt I used python3 but for you it might be called python , py or py3 .我使用了python3但对你来说它可能被称为pythonpypy3

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/指定 Python runtime.txt很重要,因为最新的 Python 版本(3.8 及更高版本)不支持ntlk ,请参阅: https : ntlk

Finally explicitely specify needed Heroku buildpacks via app.json :最后通过app.json明确指定所需的 Heroku app.json
https://devcenter.heroku.com/articles/app-json-schema 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"
  }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM