简体   繁体   English

使用python-shell无法在heroku中安装python模块

[英]Install python modules in heroku while using python-shell not working

I'm trying to import a python file into node web application. 我正在尝试将python文件导入节点Web应用程序。 On my local machine it works fine, but when I upload it to heroku, the modules don't get imported correctly, and I get an error message saying, ModuleNotFoundError: No module named 'tensorflow' . 在我的本地计算机上,它工作正常,但是当我将其上传到heroku时,模块无法正确导入,并且我收到一条错误消息,指出ModuleNotFoundError: No module named 'tensorflow'

I'm assuming that the modules are not installed. 我假设未安装模块。 So I made a requirements.txt file, and imported in python like this: 所以我做了一个requirements.txt文件,并像这样在python中导入:

import subprocess
import sys
subprocess.call([sys.executable, "-r", "pip3", "install", 'requirements.txt'])

I still get the previous error of: ModuleNotFoundError: No module named 'tensorflow' . 我仍然收到先前的错误: ModuleNotFoundError: No module named 'tensorflow' How can I install python modules in heroku while using python-shell? 如何在使用python-shell的同时在heroku中安装python模块?

Python Imports Python导入

import json
import pickle
import random
import tensorflow as tf
import tflearn
import numpy as np
import nltk
from nltk.stem.lancaster import LancasterStemmer
stemmer = LancasterStemmer()

Node 节点

const options = {
    pythonOptions: ['-u'],
    pythonPath: 'python3'
};
let pyshell = new PythonShell('./python_2/script.py', options);

Here's the full output error I'm receiving: 这是我收到的完整输出错误:

2019-09-02T19:11:03.182951+00:00 app[web.1]: events.js:174
2019-09-02T19:11:03.182964+00:00 app[web.1]: throw er; // Unhandled 'error' event
2019-09-02T19:11:03.182967+00:00 app[web.1]: ^
2019-09-02T19:11:03.182969+00:00 app[web.1]: 
2019-09-02T19:11:03.182971+00:00 app[web.1]: Error: ModuleNotFoundError: No module named 'tensorflow'
2019-09-02T19:11:03.182973+00:00 app[web.1]: at PythonShell.parseError (/app/node_modules/python-shell/index.js:260:21)
2019-09-02T19:11:03.182975+00:00 app[web.1]: at terminateIfNeeded (/app/node_modules/python-shell/index.js:139:32)
2019-09-02T19:11:03.182978+00:00 app[web.1]: at ChildProcess.<anonymous> (/app/node_modules/python-shell/index.js:131:13)
2019-09-02T19:11:03.182980+00:00 app[web.1]: at ChildProcess.emit (events.js:189:13)
2019-09-02T19:11:03.182983+00:00 app[web.1]: at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
2019-09-02T19:11:03.182985+00:00 app[web.1]: ----- Python Traceback -----
2019-09-02T19:11:03.182987+00:00 app[web.1]: File "python_2/model.py", line 5, in <module>
2019-09-02T19:11:03.182989+00:00 app[web.1]: import tensorflow as tf
2019-09-02T19:11:03.182991+00:00 app[web.1]: Emitted 'error' event at:
2019-09-02T19:11:03.182994+00:00 app[web.1]: at terminateIfNeeded (/app/node_modules/python-shell/index.js:153:26)
2019-09-02T19:11:03.182996+00:00 app[web.1]: at ChildProcess.<anonymous> (/app/node_modules/python-shell/index.js:131:13)
2019-09-02T19:11:03.182998+00:00 app[web.1]: at ChildProcess.emit (events.js:189:13)
2019-09-02T19:11:03.183000+00:00 app[web.1]: at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
2019-09-02T19:11:03.224746+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-09-02T19:11:03.225516+00:00 app[web.1]: npm ERR! errno 1
2019-09-02T19:11:03.230041+00:00 app[web.1]: npm ERR! backend@1.0.0 start: `node index.js`
2019-09-02T19:11:03.230381+00:00 app[web.1]: npm ERR! Exit status 1
2019-09-02T19:11:03.230929+00:00 app[web.1]: npm ERR!
2019-09-02T19:11:03.232455+00:00 app[web.1]: npm ERR! Failed at the backend@1.0.0 start script.
2019-09-02T19:11:03.233317+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-09-02T19:11:03.270676+00:00 app[web.1]: 
2019-09-02T19:11:03.272904+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-09-02T19:11:03.273603+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-09-02T19_11_03_247Z-debug.log

Assuming you've already configured multiple buildpacks for your app, which if you've got both node and python you likely have, you should be able to simply add tensorflow to your existing requirements.txt file to have it installed during deployment. 假设您已经为您的应用程序配置了多个buildpack,如果您同时拥有nodepython ,则应该能够简单地将tensorflow添加到现有的requirements.txt文件中,以便在部署期间进行安装。

That file should be in the root directory of your application, beside your package.json . 该文件应位于您应用程序的根目录中,位于package.json旁边。

I just added a runtime.txt file inserting: Python-3.6.5 but I'm still getting the error 我刚刚添加了一个runtime.txt文件插入:Python-3.6.5,但仍然出现错误

Your runtime.txt should also be in the root directory of your project, and your requested Python version should be all lowercase, eg 您的runtime.txt也应该位于项目的根目录中,并且所请求的Python版本应该全部为小写,例如

python-3.6.5

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

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