简体   繁体   中英

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'

My Requirement.txt using 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:

  1. You're depending on vext , a library to

    Use system python packages in virtualenv.

    It's very likely that whatever system packages you're trying to use aren't available on 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.

    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.

  2. vext.gi specifically is designed to

    Allow use of system gi.repository (Gtk3) from a virtualenv

    GTK3 is a graphical toolkit that doesn't make much sense to run on a web host. I'm not sure exactly what you're trying to do with it, but you'll probably have to rethink that approach.

  3. You're also using playsound , a

    Pure Python, cross platform, single function module with no dependencies for playing sounds

    This doesn't make much sense on Heroku, either. 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 probably won't work at all on Heroku, but if it does it will play a sound on some server in an Amazon datacenter. You won't be able to hear it.

    Like with GTK3, you're going to have to rethink this part of your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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