[英]ModuleNotFoundError: No module named 'gi' - While deploying in Heroku
I am deploying a small Flask application in Heroku and facing this error - ModuleNotFoundError: No module named 'gi' 我在Heroku中部署了一个小的Flask应用程序并遇到此错误-ModuleNotFoundError:没有名为“ gi”的模块
My Requirement.txt using pip: 我的Requirement.txt使用pip:
certifi==2019.3.9
chardet==3.0.4
Click==7.0
Flask==1.0.2
gunicorn==19.9.0
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
playsound==1.2.2
requests==2.21.0
ruamel.yaml==0.15.92
urllib3==1.24.2
vext==0.7.3
vext.gi==0.7.0
Werkzeug==0.15.2
pgi==0.0.10.1
My Actual code: 我的实际代码:
from flask import render_template
import requests
from playsound import playsound
from app import app
@app.route('/')
@app.route('/index',methods=['GET'])
def index():
counter = 1
user = {'username': 'Mr Test'}
playsound('audio.mp3')
return render_template('index.html', title='Home', user=user)
error message: 错误信息:
2019-04-19T17:52:05.415693+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/playsound.py", line 91, in _playsoundNix
2019-04-19T17:52:05.415694+00:00 app[web.1]: import gi
2019-04-19T17:52:05.415695+00:00 app[web.1]: ModuleNotFoundError: No module named 'gi'
There are at least three issues here: 这里至少存在三个问题:
You're depending on vext
, a library to 您依赖
vext
,这是一个库
Use system python packages in virtualenv.
在virtualenv中使用系统python软件包。
It's very likely that whatever system packages you're trying to use aren't available on Heroku. Heroku上可能没有您要使用的任何系统软件包。 You may be able to install them as Ubuntu packages using multiple buildpacks including the
apt
buildpack and an Aptfile
, but it probably makes more sense to just install them in your virtualenv. 您可能可以使用包括
apt
buildpack和Aptfile
在内的多个buildpack将它们作为Ubuntu软件包安装,但是仅将它们安装在virtualenv中可能更有意义。
vext
claims that some packages don't work well that way, but getting them to work in a virtualenv is probably a better thing to ask about. vext
声称有些软件包不能很好地工作,但是让它们在virtualenv中工作可能是一个更好的问题。
vext.gi
specifically is designed to vext.gi
专门用于
Allow use of system gi.repository (Gtk3) from a virtualenv
允许从virtualenv使用系统gi.repository(Gtk3)
GTK3 is a graphical toolkit that doesn't make much sense to run on a web host. GTK3是一个图形工具包,在Web主机上运行没有多大意义。 I'm not sure exactly what you're trying to do with it, but you'll probably have to rethink that approach.
我不确定您要使用它做什么,但是您可能必须重新考虑这种方法。
You're also using playsound
, a 您还使用了
playsound
Pure Python, cross platform, single function module with no dependencies for playing sounds
纯Python,跨平台,单功能模块,不依赖于播放声音
This doesn't make much sense on Heroku, either. 在Heroku上,这也没有多大意义。
playsound
might seem to work on your local machine, but that's just because your server is running on the same machine as your browser. playsound
似乎可以在您的本地计算机上运行,但这仅仅是因为您的服务器与浏览器在同一台计算机上运行。 playsound
probably won't work at all on Heroku, but if it does it will play a sound on some server in an Amazon datacenter. playsound
可能根本无法在Heroku上运行,但如果这样做,它将在Amazon数据中心的某些服务器上播放声音。 You won't be able to hear it. 您将听不到。
Like with GTK3, you're going to have to rethink this part of your application. 与GTK3一样,您将不得不重新考虑应用程序的这一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.