Flask和Heroku - ModuleNotFoundError:没有名为' app'

时间:2018-02-20 09:00:48

标签: heroku flask

我正在尝试将Flask应用部署到Heroku。部署之后,应用程序崩溃,我收到错误ModuleNotFoundError:没有名为' app'的模块。

项目结构:

.
├── ./espncricinfo
│      ├── ./exceptions.py
│      ├── ./__init__.py
│      ├── ./match.py
│      ├── ./player.py
│      ├── ./summary.py
│
├── ./pycricbuzz 
│      ├──./cricbuzz.py
│      ├──./ __init__.py
├── ./pycricket
│      ├── ./cricket.py
│      ├──./ __init__.py
├── ./static
│      ├── ./bblpics
│      ├── ./fonts
│      ├── ./images
│      ├── ./favascripts
│      ├── ./stylesheets
├── ./templates    
│      ├── ./index.html
│      ├── ./base.html
│      ├── ./app.html
│      ├── ./Smmary.html
│      ├── ./Scorecard.html
│      ├── ./News.html
├── ./__init__.py
│
├── ./Procfile
│
├── ./requirements.txt
│
├── ./runtime.txt
│
├── ./bbl.py
│    
└── ./score.py

我在virtualenv做 我点了安装这些依赖 pip安装烧瓶 pip安装请求 pip安装pytz pip install praw pip安装beautifulsoup4 pip install google-api-python-client pip install python-dateutil pip install python-espncricinfo pip安装熊猫 pip安装gunicorn

pip freeze > requirements.txt
echo web: gunicorn app:app > Procfile
echo python-3.6.4 >runtime.txt

git init
heroku login
heroku create the-wall-cricket-scores
git add .
git commit -m "fdf"
git push heroku master
heroku open

这是我的主要 init .py

 app = Flask(__name__)



    if __name__=="__main__":
        app.run(debug=True)

Procfile web:gunicorn app:app     runtime.txt python-3.6.4

Requirements.txt -

beautifulsoup4==4.6.0
bs4==0.0.1
certifi==2018.1.18
chardet==3.0.4
click==6.7
dateparser==0.7.0
Flask==0.12.2
google-api-python-client==1.6.5
gunicorn==19.7.1
httplib2==0.10.3
idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
numpy==1.14.0
oauth2client==4.1.2
pandas==0.22.0
praw==5.3.0
prawcore==0.13.0
pyasn1==0.4.2
pyasn1-modules==0.2.1
python-dateutil==2.6.1
python-espncricinfo==0.3.1
pytz==2018.3
regex==2018.2.8
requests==2.18.4
rsa==3.4.2
six==1.11.0
tzlocal==1.5.1
update-checker==0.16
uritemplate==3.0.0
urllib3==1.22
Werkzeug==0.14.1

我收到如下错误: 错误完整详情:

2018-02-20T06:52:40.000000+00:00 app[api]: Build succeeded
2018-02-20T06:54:00.350992+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
2018-02-20T06:54:01.598198+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
2018-02-20T06:54:03.409972+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [4] [INFO] Starting gunicorn 19.7.1
2018-02-20T06:54:03.413413+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [4] [INFO] Listening at: http://0.0.0.0:34331 (4)
2018-02-20T06:54:03.413643+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [4] [INFO] Using worker: sync
2018-02-20T06:54:03.420766+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [8] [INFO] Booting worker with pid: 8
2018-02-20T06:54:03.431463+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [8] [ERROR] Exception in worker process
2018-02-20T06:54:03.431467+00:00 app[web.1]: Traceback (most recent call last):
2018-02-20T06:54:03.431469+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
2018-02-20T06:54:03.431471+00:00 app[web.1]:     worker.init_process()
2018-02-20T06:54:03.431473+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 126, in init_process
2018-02-20T06:54:03.431474+00:00 app[web.1]:     self.load_wsgi()
2018-02-20T06:54:03.431476+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
2018-02-20T06:54:03.431478+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2018-02-20T06:54:03.431480+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2018-02-20T06:54:03.431482+00:00 app[web.1]:     self.callable = self.load()
2018-02-20T06:54:03.431483+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2018-02-20T06:54:03.431485+00:00 app[web.1]:     return self.load_wsgiapp()
2018-02-20T06:54:03.431487+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2018-02-20T06:54:03.431489+00:00 app[web.1]:     return util.import_app(self.app_uri)
2018-02-20T06:54:03.431490+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 352, in import_app
2018-02-20T06:54:03.431492+00:00 app[web.1]:     __import__(module)
2018-02-20T06:54:03.431534+00:00 app[web.1]: ModuleNotFoundError: No module named 'app'
2018-02-20T06:54:03.431765+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [8] [INFO] Worker exiting (pid: 8)
2018-02-20T06:54:03.473017+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [9] [INFO] Booting worker with pid: 9
2018-02-20T06:54:03.484252+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [9] [ERROR] Exception in worker process
2018-02-20T06:54:03.484255+00:00 app[web.1]: Traceback (most recent call last):
2018-02-20T06:54:03.484257+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
2018-02-20T06:54:03.484258+00:00 app[web.1]:     worker.init_process()
2018-02-20T06:54:03.484260+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 126, in init_process
2018-02-20T06:54:03.484262+00:00 app[web.1]:     self.load_wsgi()
2018-02-20T06:54:03.484263+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
2018-02-20T06:54:03.484265+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2018-02-20T06:54:03.484267+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2018-02-20T06:54:03.484268+00:00 app[web.1]:     self.callable = self.load()
2018-02-20T06:54:03.484270+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2018-02-20T06:54:03.484271+00:00 app[web.1]:     return self.load_wsgiapp()
2018-02-20T06:54:03.484273+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2018-02-20T06:54:03.484275+00:00 app[web.1]:     return util.import_app(self.app_uri)
2018-02-20T06:54:03.484277+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 352, in import_app
2018-02-20T06:54:03.484278+00:00 app[web.1]:     __import__(module)
2018-02-20T06:54:03.484338+00:00 app[web.1]: ModuleNotFoundError: No module named 'app'
2018-02-20T06:54:03.484677+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [9] [INFO] Worker exiting (pid: 9)
2018-02-20T06:54:03.590746+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [4] [INFO] Shutting down: Master
2018-02-20T06:54:03.590997+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [4] [INFO] Reason: Worker failed to boot.
2018-02-20T06:54:03.801591+00:00 heroku[web.1]: Process exited with status 3
2018-02-20T06:54:04.041064+00:00 heroku[web.1]: State changed from starting to crashed
2018-02-20T06:54:04.029283+00:00 heroku[web.1]: Process exited with status 3
2018-02-20T06:54:03.896607+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [4] [INFO] Starting gunicorn 19.7.1
2018-02-20T06:54:03.897225+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [4] [INFO] Listening at: http://0.0.0.0:13017 (4)
2018-02-20T06:54:03.897355+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [4] [INFO] Using worker: sync
2018-02-20T06:54:03.901981+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [8] [INFO] Booting worker with pid: 8
2018-02-20T06:54:03.907379+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [8] [ERROR] Exception in worker process
2018-02-20T06:54:03.907383+00:00 app[web.1]: Traceback (most recent call last):
2018-02-20T06:54:03.907385+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
2018-02-20T06:54:03.907387+00:00 app[web.1]:     worker.init_process()
2018-02-20T06:54:03.907389+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 126, in init_process
2018-02-20T06:54:03.907391+00:00 app[web.1]:     self.load_wsgi()
2018-02-20T06:54:03.907393+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
2018-02-20T06:54:03.907394+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2018-02-20T06:54:03.907396+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2018-02-20T06:54:03.907398+00:00 app[web.1]:     self.callable = self.load()
2018-02-20T06:54:03.907400+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2018-02-20T06:54:03.907402+00:00 app[web.1]:     return self.load_wsgiapp()
2018-02-20T06:54:03.907404+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2018-02-20T06:54:03.907406+00:00 app[web.1]:     return util.import_app(self.app_uri)
2018-02-20T06:54:03.907408+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 352, in import_app
2018-02-20T06:54:03.907410+00:00 app[web.1]:     __import__(module)
2018-02-20T06:54:03.907417+00:00 app[web.1]: ModuleNotFoundError: No module named 'app'
2018-02-20T06:54:03.907561+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [8] [INFO] Worker exiting (pid: 8)
2018-02-20T06:54:03.950849+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [4] [INFO] Shutting down: Master
2018-02-20T06:54:03.950970+00:00 app[web.1]: [2018-02-20 06:54:03 +0000] [4] [INFO] Reason: Worker failed to boot.
2018-02-20T06:54:48.667089+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=the-wall-cricket.herokuapp.com request_id=ac09678c-ef2d-4f3a-9d96-f0c60232eef3 fwd="157.49.23.47" dyno= connect= service= status=503 bytes= protocol=https
2018-02-20T06:54:51.281797+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=the-wall-cricket.herokuapp.com request_id=c779ab65-1b04-443a-b17b-438cfe914a17 fwd="157.49.23.47" dyno= connect= service= status=503 bytes= protocol=https
2018-02-20T06:54:51.189245+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/robots.txt" host=the-wall-cricket.herokuapp.com request_id=6d88e51d-44c6-4389-aac5-c24595aad59c fwd="157.49.105.219" dyno= connect= service= status=503 bytes= protocol=https
2018-02-20T06:54:51.849753+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/robots.txt" host=the-wall-cricket.herokuapp.com request_id=501e291a-0426-477b-ab30-b9e2c00865fb fwd="157.49.23.47" dyno= connect= service= status=503 bytes= protocol=https
2018-02-20T06:54:52.823503+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/robots.txt" host=the-wall-cricket.herokuapp.com request_id=7173cf2e-806d-4675-8e9e-442624e55f1c fwd="157.49.23.47" dyno= connect= service= status=503 bytes= protocol=https

这有什么问题,我怎样才能成功部署应用程序?

3 个答案:

答案 0 :(得分:2)

就我而言,这是在我进行了以下更改之后解决的,当然,在将其提交到heroku之前先进行了更改:

1)运行了[56, 77, 77, 77, 77, 77, 77, 99]

2)将我的pip freeze > requirements.txt移到另一个目录,并更新了app.pyProcfile-所有导入app.py-的文件,并反映了新位置。我不确定移动文件是否确实起到了作用,这似乎不太可能,但是无论如何,值得验证所有导入manage.py的文件都具有正确的路径

答案 1 :(得分:1)

web:gunicorn app:app是标准的Procfile。它希望您的.py文件应命名为app.py。

如果要更改.py名称,还应该更改Procfile。 web:gunicorn my_app_name:app 之后,您可以命名文件-my_app_name.py

答案 2 :(得分:1)

在本地计算机上,在存储库的基础上,您需要添加一个Procfile(完全像这样)。

在其中,仅粘贴一行: 网址:gunicorn:app

示例:如果要触发init.py,则:

web: gunicorn init:app