使用python-shell无法在heroku中安装python模块 [英] Install python modules in heroku while using python-shell not working

查看:79
本文介绍了使用python-shell无法在heroku中安装python模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将python文件导入节点Web应用程序.在我的本地计算机上,它工作正常,但是当我将其上传到heroku时,模块无法正确导入,并且我收到一条错误消息,提示ModuleNotFoundError: No module named 'tensorflow'.

I'm trying to import a python file into node web application. 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'.

我假设未安装模块.所以我制作了一个requirements.txt文件,并像这样在python中导入:

I'm assuming that the modules are not installed. So I made a requirements.txt file, and imported in python like this:

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

我仍然收到先前的错误:ModuleNotFoundError: No module named 'tensorflow'.如何在使用python-shell的同时在heroku中安装python模块?

I still get the previous error of: ModuleNotFoundError: No module named 'tensorflow'. How can I install python modules in heroku while using python-shell?

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

节点

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

推荐答案

假设您已经为您的应用配置了多个buildpack,如果您同时拥有nodepython,则应该只需将tensorflow添加到现有的requirements.txt文件中,即可在部署过程中进行安装.

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.

该文件应位于应用程序的根目录中,位于package.json旁边.

That file should be in the root directory of your application, beside your package.json.

我刚刚添加了一个runtime.txt文件,插入其中:Python-3.6.5,但仍然出现错误

I just added a runtime.txt file inserting: Python-3.6.5 but I'm still getting the error

您的runtime.txt也应位于项目的根目录中,并且您请求的Python版本应全部为小写字母,例如

Your runtime.txt should also be in the root directory of your project, and your requested Python version should be all lowercase, e.g.

python-3.6.5

这篇关于使用python-shell无法在heroku中安装python模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆