无法将 Flask 应用推送到 Heroku口袋狮身人面像

问题描述

我正在尝试将 Flask 应用程序部署到 heroku。尝试安装pocketsphinx时似乎失败了。

该项目在我的本地机器上运行良好,但无法部署。

我该如何解决

Enumerating objects: 659,done.
Counting objects: 100% (659/659),done.
Delta compression using up to 4 threads
Compressing objects: 100% (615/615),done.
Writing objects: 100% (659/659),58.57 MiB | 329.00 KiB/s,done.
Total 659 (delta 69),reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Python app detected
remote: -----> Using Python version specified in runtime.txt
remote:  !     Python has released a security update! Please consider upgrading to python-3.8.10
remote:        Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing python-3.8.5
remote: -----> Installing pip 20.2.4,setuptools 47.1.1 and wheel 0.36.2
remote: -----> Installing sqlite3
remote: -----> Installing requirements with pip
remote:        Collecting blinker==1.4
remote:          Downloading blinker-1.4.tar.gz (111 kB)
remote:        Collecting click==8.0.1
remote:          Downloading click-8.0.1-py3-none-any.whl (97 kB)
remote:        Collecting Flask==2.0.1
remote:          Downloading Flask-2.0.1-py3-none-any.whl (94 kB)
remote:        Collecting flask-requests==0.0.14
remote:          Downloading flask_requests-0.0.14.tar.gz (2.0 kB)
remote:        Collecting gunicorn==20.1.0
remote:          Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
remote:        Collecting itsdangerous==2.0.1
remote:          Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
remote:        Collecting Jinja2==3.0.1
remote:          Downloading Jinja2-3.0.1-py3-none-any.whl (133 kB)
remote:        Collecting MarkupSafe==2.0.1
remote:          Downloading MarkupSafe-2.0.1-cp38-cp38-manylinux2010_x86_64.whl (30 kB)
remote:        Collecting pampy==0.3.0
remote:          Downloading pampy-0.3.0-py3-none-any.whl (17 kB)
remote:        Collecting pocketsphinx==0.1.15
remote:          Downloading pocketsphinx-0.1.15.tar.gz (29.1 MB)
remote:        Collecting PyAudio==0.2.11
remote:          Downloading PyAudio-0.2.11.tar.gz (37 kB)
remote:        Collecting SpeechRecognition==3.8.1
remote:          Downloading SpeechRecognition-3.8.1-py2.py3-none-any.whl (32.8 MB)
remote:        Collecting Werkzeug==2.0.1
remote:          Downloading Werkzeug-2.0.1-py3-none-any.whl (288 kB)
remote:        Building wheels for collected packages: blinker,flask-requests,pocketsphinx,PyAudio
remote:          Building wheel for blinker (setup.py): started
remote:          Building wheel for blinker (setup.py): finished with status 'done'
remote:          Created wheel for blinker: filename=blinker-1.4-py3-none-any.whl size=13451 sha256=15507a064de16ed40eb2d9b3dee91a100290bd99a6f4ea39ca7fd1b86226bec8
remote:          Stored in directory: /tmp/pip-ephem-wheel-cache-fhg6_ns3/wheels/b7/a5/68/fe632054a5eadd531c7a49d740c50eb6adfbeca822b4eab8d4
remote:          Building wheel for flask-requests (setup.py): started
remote:          Building wheel for flask-requests (setup.py): finished with status 'done'
remote:          Created wheel for flask-requests: filename=flask_requests-0.0.14-py3-none-any.whl size=2414 sha256=74d09e95b3350728bc972941620ee5dd7d56d158c372b07e10b51ed121abbd5f
remote:          Stored in directory: /tmp/pip-ephem-wheel-cache-fhg6_ns3/wheels/c4/c9/a7/aaeb7dad02f88405532951bebd7901c02dc11059e0b331a060
remote:          Building wheel for pocketsphinx (setup.py): started
remote:          Building wheel for pocketsphinx (setup.py): finished with status 'error'
remote:          ERROR: Command errored out with exit status 1:
remote:           command: /app/.heroku/python/bin/python -u -c 'import sys,setuptools,tokenize; sys.argv[0] = '"'"'/tmp/pip-install-7ik6237u/pocketsphinx/setup.py'"'"'; __file__='"'"'/tmp/pip-install-7ik6237u/pocketsphinx/setup.py'"'"';f=getattr(tokenize,'"'"'open'"'"',open)(__file__);code=f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(compile(code,__file__,'"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-n13un_3i
remote:               cwd: /tmp/pip-install-7ik6237u/pocketsphinx/
remote:          Complete output (7 lines):
remote:          running bdist_wheel
remote:          running build_ext
remote:          building 'sphinxbase._sphinxbase' extension
remote:          swigging deps/sphinxbase/swig/sphinxbase.i to deps/sphinxbase/swig/sphinxbase_wrap.c
remote:          swig -python -modern -threads -Ideps/sphinxbase/include -Ideps/sphinxbase/include/sphinxbase -Ideps/sphinxbase/include/android -Ideps/sphinxbase/swig -outdir sphinxbase -o deps/sphinxbase/swig/sphinxbase_wrap.c deps/sphinxbase/swig/sphinxbase.i
remote:          unable to execute 'swig': Permission denied
remote:          error: command 'swig' Failed with exit status 1
remote:          ----------------------------------------
remote:          ERROR: Failed building wheel for pocketsphinx
remote:          Running setup.py clean for pocketsphinx
remote:          Building wheel for PyAudio (setup.py): started
remote:          Building wheel for PyAudio (setup.py): finished with status 'error'
remote:          ERROR: Command errored out with exit status 1:
remote:           command: /app/.heroku/python/bin/python -u -c 'import sys,tokenize; sys.argv[0] = '"'"'/tmp/pip-install-7ik6237u/pyaudio/setup.py'"'"'; __file__='"'"'/tmp/pip-install-7ik6237u/pyaudio/setup.py'"'"';f=getattr(tokenize,'"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-a0cgqlw1
remote:               cwd: /tmp/pip-install-7ik6237u/pyaudio/
remote:          Complete output (16 lines):
remote:          running bdist_wheel
remote:          running build
remote:          running build_py
remote:          creating build
remote:          creating build/lib.linux-x86_64-3.8
remote:          copying src/pyaudio.py -> build/lib.linux-x86_64-3.8
remote:          running build_ext
remote:          building '_portaudio' extension
remote:          creating build/temp.linux-x86_64-3.8
remote:          creating build/temp.linux-x86_64-3.8/src
remote:          gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/app/.heroku/python/include/python3.8 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.8/src/_portaudiomodule.o
remote:          src/_portaudiomodule.c:29:10: Fatal error: portaudio.h: No such file or directory
remote:             29 | #include "portaudio.h"
remote:                |          ^~~~~~~~~~~~~
remote:          compilation terminated.
remote:          error: command 'gcc' Failed with exit status 1
remote:          ----------------------------------------
remote:          ERROR: Failed building wheel for PyAudio
remote:          Running setup.py clean for PyAudio
remote:        Successfully built blinker flask-requests
remote:        Failed to build pocketsphinx PyAudio
remote:        Installing collected packages: blinker,click,MarkupSafe,Jinja2,itsdangerous,Werkzeug,Flask,pampy,gunicorn,PyAudio,SpeechRecognition
remote:            Running setup.py install for pocketsphinx: started
remote:            Running setup.py install for pocketsphinx: finished with status 'error'
remote:            ERROR: Command errored out with exit status 1:
remote:             command: /app/.heroku/python/bin/python -u -c 'import sys,'"'"'exec'"'"'))' install --record /tmp/pip-record-xdfr6a6a/install-record.txt --single-version-externally-managed --compile --install-headers /app/.heroku/python/include/python3.8/pocketsphinx
remote:                 cwd: /tmp/pip-install-7ik6237u/pocketsphinx/
remote:            Complete output (7 lines):
remote:            running install
remote:            running build_ext
remote:            building 'sphinxbase._sphinxbase' extension
remote:            swigging deps/sphinxbase/swig/sphinxbase.i to deps/sphinxbase/swig/sphinxbase_wrap.c
remote:            swig -python -modern -threads -Ideps/sphinxbase/include -Ideps/sphinxbase/include/sphinxbase -Ideps/sphinxbase/include/android -Ideps/sphinxbase/swig -outdir sphinxbase -o deps/sphinxbase/swig/sphinxbase_wrap.c deps/sphinxbase/swig/sphinxbase.i
remote:            unable to execute 'swig': Permission denied
remote:            error: command 'swig' Failed with exit status 1
remote:            ----------------------------------------
remote:        ERROR: Command errored out with exit status 1: /app/.heroku/python/bin/python -u -c 'import sys,'"'"'exec'"'"'))' install --record /tmp/pip-record-xdfr6a6a/install-record.txt --single-version-externally-managed --compile --install-headers /app/.heroku/python/include/python3.8/pocketsphinx Check the logs for full command output.
remote:  !     Push rejected,Failed to compile Python app.
remote: 
remote:  !     Push Failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to demo-sr-project.
remote: 
To https://git.heroku.com/demo-sr-project.git
 ! [remote rejected] master -> master (pre-receive hook declined)

我认为问题在于安装pocketsphinx。 我在本地机器上运行 heroku local web 并且它运行,但我无法将它部署到 heroku。

requiremnets.txt

blinker==1.4
click==8.0.1
Flask==2.0.1
flask-requests==0.0.14
gunicorn==20.1.0
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
pampy==0.3.0
pocketsphinx==0.1.15
PyAudio==0.2.11
SpeechRecognition==3.8.1
Werkzeug==2.0.1

资料

web: gunicorn wsgi:app

运行时.txt

python-3.8.5

解决方法

根据错误日志,看来你需要在heroku机器上安装一个linux依赖项。

PyAudio docs 开始,在 ubuntu 上你需要安装两个包:python-pyaudio 和 python3-pyaudio。

很简单,在requirements.txt旁边添加一个名为“Aptfile”的新文件,并将linux包名称添加到文件中。

因此,在您的情况下,该文件将仅具有:

python-pyaudio
python3-pyaudio

在里面。

然后 heroku 将在尝试安装您的应用之前安装这些包。

您可能需要在 heroku 中添加 buildpack