简体   繁体   English

'ImportError:没有名为'的模块,heroku上的flask

[英]'ImportError: No module named ' , flask on heroku

在此处输入图片说明

I am working on a flask app with a structure as in the screenshot based on http://code.tutsplus.com/tutorials/an-introduction-to-pythons-flask-framework--net-28822 . 我正在开发一个烧瓶应用程序,其结构如http://code.tutsplus.com/tutorials/an-introduction-to-pythons-flask-framework--net-28822所示 To get this working locally I've been running the routes.py file. 为了使它在本地工作,我一直在运行routes.py文件。

I'm now trying to deploy on heroku using gunicorn following https://www.udacity.com/wiki/ud330/deploy . 我现在正在按照https://www.udacity.com/wiki/ud330/deploy的要求使用gunicorn在heroku上进行部署。 Following the directions, My requirements.txt contains: 按照指示进行操作,我的requirements.txt包含:

$ pip Freeze
Flask==0.10.1
Flask-Mail==0.9.1
Flask-SQLAlchemy==2.1
Flask-WTF==0.12
Jinja2==2.8
MarkupSafe==0.23
SQLAlchemy==1.0.11
WTForms==2.1
Werkzeug==0.11.3
blinker==1.4
gunicorn==19.4.5
itsdangerous==0.24

I'm not sure what to put into my Procfile , I've tried several variations including: 我不确定要在Procfile中放入什么内容,我尝试了几种变体,包括:

web: gunicorn mini:intro_to_flask 

But I'm getting the following in the heroku logs: 但是我在heroku日志中得到了以下内容:

←[32m2016-01-23T17:15:39.572265+00:00 app[web.1]:←[0m ImportError: No module named mi
ni
←[32m2016-01-23T17:15:39.652562+00:00 app[web.1]:←[0m     super(Application, self).ru
n()
←[32m2016-01-23T17:15:39.652583+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
←[32m2016-01-23T17:15:39.652835+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/arbiter.py", line 347, in stop
←[32m2016-01-23T17:15:39.572260+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
←[32m2016-01-23T17:15:39.652807+00:00 app[web.1]:←[0m     self.stop()
←[32m2016-01-23T17:15:39.652914+00:00 app[web.1]:←[0m     time.sleep(0.1)
←[32m2016-01-23T17:15:39.653207+00:00 app[web.1]:←[0m gunicorn.errors.HaltServer: <Ha
ltServer 'Worker failed to boot.' 3>
←[32m2016-01-23T17:15:40.600197+00:00 heroku[web.1]:←[0m State changed from starting
to crashed
←[32m2016-01-23T17:15:40.576720+00:00 heroku[web.1]:←[0m Process exited with status 1

Also my runserver.py file contains: 我的runserver.py文件还包含:

from intro_to_flask import app

app.run(debug=True)

How can I fix this? 我怎样才能解决这个问题?

edit changed Procfile to: 将更改的Procfile编辑为:

web: gunicorn runserver:app

Now getting: 现在得到:

←[32m2016-01-23T17:47:43.545434+00:00 app[web.1]:←[0m     from intro_to_flask import
app
←[32m2016-01-23T17:47:43.545435+00:00 app[web.1]:←[0m ImportError: No module named in
tro_to_flask
←[32m2016-01-23T17:47:43.545435+00:00 app[web.1]:←[0m Traceback (most recent call las
t):
←[32m2016-01-23T17:47:43.545436+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
←[32m2016-01-23T17:47:43.545438+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
←[32m2016-01-23T17:47:43.545437+00:00 app[web.1]:←[0m     worker.init_process()
←[32m2016-01-23T17:47:43.545438+00:00 app[web.1]:←[0m     self.load_wsgi()
←[32m2016-01-23T17:47:43.545439+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
←[32m2016-01-23T17:47:43.545440+00:00 app[web.1]:←[0m     self.wsgi = self.app.wsgi()

←[32m2016-01-23T17:47:43.545440+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
←[32m2016-01-23T17:47:43.545441+00:00 app[web.1]:←[0m     self.callable = self.load()

←[32m2016-01-23T17:47:43.545442+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
←[32m2016-01-23T17:47:43.545442+00:00 app[web.1]:←[0m     return self.load_wsgiapp()
←[32m2016-01-23T17:47:43.545443+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
←[32m2016-01-23T17:47:43.545444+00:00 app[web.1]:←[0m     return util.import_app(self

edit2: EDIT2:

made the change to a normal '__init__.py' . 更改为普通的'__init__.py'。 intro_to_flask now registering as a module: intro_to_flask现在注册为模块:

←[36m2016-01-23T18:15:18.071418+00:00 app[web.1]:←[0m     from intro_to_flask import
app
←[36m2016-01-23T18:15:18.150803+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
←[36m2016-01-23T18:15:18.150846+00:00 app[web.1]:←[0m     WSGIApplication("%(prog)s [
OPTIONS] [APP_MODULE]").run()
←[36m2016-01-23T18:15:18.071419+00:00 app[web.1]:←[0m ImportError: cannot import name
 app
←[36m2016-01-23T18:15:18.071605+00:00 app[web.1]:←[0m [2016-01-23 18:15:18 +0000] [10
] [INFO] Worker exiting (pid: 10)
←[36m2016-01-23T18:15:18.150976+00:00 app[web.1]:←[0m     Arbiter(self).run()
←[36m2016-01-23T18:15:18.150712+00:00 app[web.1]:←[0m Traceback (most recent call las
t):
←[36m2016-01-23T18:15:18.151078+00:00 app[web.1]:←[0m     self.halt(reason=inst.reaso
n, exit_status=inst.exit_status)
←[36m2016-01-23T18:15:18.150718+00:00 app[web.1]:←[0m   File "/app/.heroku/python/bin
/gunicorn", line 11, in <module>
←[36m2016-01-23T18:15:18.151098+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/arbiter.py", line 302, in halt
←[36m2016-01-23T18:15:18.150773+00:00 app[web.1]:←[0m     sys.exit(run())
←[36m2016-01-23T18:15:18.151169+00:00 app[web.1]:←[0m     self.stop()
←[36m2016-01-23T18:15:18.151172+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/arbiter.py", line 347, in stop
←[36m2016-01-23T18:15:18.151267+00:00 app[web.1]:←[0m     time.sleep(0.1)
←[36m2016-01-23T18:15:18.150869+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/app/base.py", line 192, in run
←[36m2016-01-23T18:15:18.151289+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/arbiter.py", line 219, in handle_chld
←[36m2016-01-23T18:15:18.150923+00:00 app[web.1]:←[0m     super(Application, self).ru
n()
←[36m2016-01-23T18:15:18.151342+00:00 app[web.1]:←[0m     self.reap_workers()
←[36m2016-01-23T18:15:18.150943+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
←[36m2016-01-23T18:15:18.151362+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/arbiter.py", line 464, in reap_workers
←[36m2016-01-23T18:15:18.150998+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/gunicorn/arbiter.py", line 206, in run
←[36m2016-01-23T18:15:18.151520+00:00 app[web.1]:←[0m gunicorn.errors.HaltServer: <Ha
ltServer 'Worker failed to boot.' 3>
←[36m2016-01-23T18:15:18.151455+00:00 app[web.1]:←[0m     raise HaltServer(reason, se
lf.WORKER_BOOT_ERROR)
←[36m2016-01-23T18:15:19.049307+00:00 heroku[web.1]:←[0m Process exited with status 1

←[36m2016-01-23T18:15:19.061843+00:00 heroku[web.1]:←[0m State changed from starting
to crashed

edit 3: 编辑3:

←[36m2016-01-23T19:14:56.910512+00:00 app[web.1]:←[0m     from intro_to_flask import
routes
←[36m2016-01-23T19:14:56.910513+00:00 app[web.1]:←[0m   File "/app/intro_to_flask/rou
tes.py", line 123, in <module>
←[36m2016-01-23T19:14:56.910513+00:00 app[web.1]:←[0m     app.run()
←[36m2016-01-23T19:14:56.910514+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/flask/app.py", line 772, in run
←[36m2016-01-23T19:14:56.910515+00:00 app[web.1]:←[0m     run_simple(host, port, self
, **options)
←[36m2016-01-23T19:14:56.910515+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/werkzeug/serving.py", line 692, in run_simple
←[36m2016-01-23T19:14:56.910516+00:00 app[web.1]:←[0m     inner()
←[36m2016-01-23T19:14:56.910516+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/werkzeug/serving.py", line 654, in inner
←[36m2016-01-23T19:14:56.910517+00:00 app[web.1]:←[0m     fd=fd)
←[36m2016-01-23T19:14:56.910518+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/werkzeug/serving.py", line 548, in make_server
←[36m2016-01-23T19:14:56.910518+00:00 app[web.1]:←[0m     passthrough_errors, ssl_con
text, fd=fd)
←[36m2016-01-23T19:14:56.910519+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/site-packages/werkzeug/serving.py", line 462, in __init__
←[36m2016-01-23T19:14:56.910523+00:00 app[web.1]:←[0m     HTTPServer.__init__(self, (
host, int(port)), handler)
←[36m2016-01-23T19:14:56.910524+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/SocketServer.py", line 420, in __init__
←[36m2016-01-23T19:14:56.910525+00:00 app[web.1]:←[0m     self.server_bind()
←[36m2016-01-23T19:14:56.910526+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/BaseHTTPServer.py", line 108, in server_bind
←[36m2016-01-23T19:14:56.910526+00:00 app[web.1]:←[0m     SocketServer.TCPServer.serv
er_bind(self)
←[36m2016-01-23T19:14:56.910527+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/SocketServer.py", line 434, in server_bind
←[36m2016-01-23T19:14:56.910528+00:00 app[web.1]:←[0m     self.socket.bind(self.serve
r_address)
←[36m2016-01-23T19:14:56.910529+00:00 app[web.1]:←[0m   File "/app/.heroku/python/lib
/python2.7/socket.py", line 228, in meth
←[36m2016-01-23T19:14:56.910529+00:00 app[web.1]:←[0m     return getattr(self._sock,n
ame)(*args)
←[36m2016-01-23T19:14:56.910548+00:00 app[web.1]:←[0m error: [Errno 98] Address alrea
dy in use
←[36m2016-01-23T19:14:56.910686+00:00 app[web.1]:←[0m [2016-01-23 19:14:56 +0000] [10
] [INFO] Worker exiting (pid: 10)
←[36m2016-01-23T19:14:57.199826+00:00 heroku[web.1]:←[0m State changed from starting
to up

If you are creating your application instance from flask in file intro_to_flask and name of your instance variable is app: 如果要通过intro_to_flask文件中的flask创建应用程序实例,并且实例变量的名称为app:

intro_to_flask.py intro_to_flask.py

...
app = Flask()
...

Change the Procfile to this 将Procfile更改为此

web: gunicorn intro_to_flask:app

The thing you need to point at is the app object, which as you show is inside the runserver file. 您需要指向的是app对象,如您所显示,该对象位于runserver文件中。 So: 所以:

gunicorn runserver:app

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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