【问题标题】:foreman start no module named myapp工头没有启动名为 myapp 的模块
【发布时间】:2014-03-19 20:10:11
【问题描述】:

我在这里关注 heroku 快速入门指南: https://devcenter.heroku.com/articles/getting-started-with-python

我被困在工头开始部分。这是我的目录的样子。我只是在运行一个基本的网络应用程序。没有框架或任何东西。

soapbar/
    Procfile.txt
    soapbar/
        soapbar.py
    venv/
        Include/
        Lib/
        Scripts/ 

这是堆栈跟踪:

16:00:13 web.1  | started with pid 34135
16:00:13 web.1  | 2014-03-19 16:00:13 [34135] [INFO] Starting gunicorn 18.0    
16:00:13 web.1  | 2014-03-19 16:00:13 [34135] [INFO] Listening at: http://0.0.0.0:5000 (34135)
16:00:13 web.1  | 2014-03-19 16:00:13 [34135] [INFO] Using worker: sync
16:00:13 web.1  | 2014-03-19 16:00:13 [34138] [INFO] Booting worker with pid: 34138
16:00:13 web.1  | 2014-03-19 16:00:13 [34138] [ERROR] Exception in worker process:
16:00:13 web.1  | Traceback (most recent call last):
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
16:00:13 web.1  |     worker.init_process()
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
16:00:13 web.1  |     self.wsgi = self.app.wsgi()
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
16:00:13 web.1  |     self.callable = self.load()
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
16:00:13 web.1  |     return self.load_wsgiapp()
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
16:00:13 web.1  |     return util.import_app(self.app_uri)
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
16:00:13 web.1  |     __import__(module)
16:00:13 web.1  | ImportError: No module named soapbar
16:00:13 web.1  | Traceback (most recent call last):
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
16:00:13 web.1  |     worker.init_process()
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
16:00:13 web.1  |     self.wsgi = self.app.wsgi()
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
16:00:13 web.1  |     self.callable = self.load()
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
16:00:13 web.1  |     return self.load_wsgiapp()
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
16:00:13 web.1  |     return util.import_app(self.app_uri)
16:00:13 web.1  |   File "/Users/ranuka/soapbar/venv/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
16:00:13 web.1  |     __import__(module)
16:00:13 web.1  | ImportError: No module named soapbar
16:00:13 web.1  | 2014-03-19 16:00:13 [34138] [INFO] Worker exiting (pid: 34138)
16:00:13 web.1  | 2014-03-19 16:00:13 [34135] [INFO] Shutting down: Master
16:00:13 web.1  | 2014-03-19 16:00:13 [34135] [INFO] Reason: Worker failed to boot.
16:00:13 web.1  | exited with code 3
16:00:13 system | sending SIGTERM to all processes
SIGTERM received

有什么想法吗?

【问题讨论】:

    标签: python heroku flask foreman


    【解决方案1】:

    将名为 __init__.py 的文件添加到 soapbar/ 文件夹。留空。

    __init__.py 文件是让 Python 处理 包含包的目录;这样做是为了防止 无意中使用通用名称(例如字符串)的目录 隐藏稍后出现在模块搜索路径上的有效模块。在 最简单的情况,__init__.py 可以只是一个空文件,但它可以 还执行包的初始化代码或设置__all__ 变量。

    来源:http://docs.python.org/2/tutorial/modules.html

    【讨论】:

    • 我想你的意思是一个名为__init__.py的文件。
    • 嗨,你知道我应该把我的申请贴在哪里吗?我的应用程序加载失败,找不到应用程序:'soapbar'
    • 我不明白你的意思。你能描述一下你正在尝试做什么,以及你得到了什么确切的错误吗? “坚持”我的申请是什么意思?你的意思是放在哪个文件夹里?您使用的目录树似乎没问题。
    • 我添加的更改仍然不能解决问题。现在我收到一个新错误,gunicorn 找不到我的应用程序,即 soapbar.py
    • 这是我用堆栈跟踪和所有内容创建的新帖子的链接。 stackoverflow.com/questions/22534552/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-08
    • 1970-01-01
    • 2017-06-30
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多