2016-12-01 55 views
1

第一次在這裏使用Heroku。我想承載一個python Flask應用程序。開始瞭解事情的工作方式。 我想通過heroku local命令在本地測試我的應用程序,但我得到這個錯誤:如何在本地測試Heroku python應用程序? ImportError:沒有名爲wsgi的模塊

ImportError: No module named wsgi

這裏是我的文件:

Procfile:

web: gunicorn choposcope.wsgi --log-file - 

myapp.wsgi :

from choposcope import app as application 

錯誤堆棧跟蹤:

[2016-12-01 18:36:21 +0100] [9916] [INFO] Starting gunicorn 19.6.0 
6:36:21 PM web.1 | [2016-12-01 18:36:21 +0100] [9916] [INFO] Listening at: http://0.0.0.0:5000 (9916) 
6:36:21 PM web.1 | [2016-12-01 18:36:21 +0100] [9916] [INFO] Using worker: sync 
6:36:21 PM web.1 | [2016-12-01 18:36:21 +0100] [9919] [INFO] Booting worker with pid: 9919 
6:36:34 PM web.1 | [2016-12-01 18:36:34 +0100] [9919] [ERROR] Exception in worker process 
6:36:34 PM web.1 | Traceback (most recent call last): 
6:36:34 PM web.1 | File "/Users/Yann/Documents/dev/choposcope/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker 
6:36:34 PM web.1 |  worker.init_process() 
6:36:34 PM web.1 | File "/Users/Yann/Documents/dev/choposcope/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process 
6:36:34 PM web.1 |  self.load_wsgi() 
6:36:34 PM web.1 | File "/Users/Yann/Documents/dev/choposcope/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi 
6:36:34 PM web.1 |  self.wsgi = self.app.wsgi() 
6:36:34 PM web.1 | File "/Users/Yann/Documents/dev/choposcope/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi 
6:36:34 PM web.1 |  self.callable = self.load() 
6:36:34 PM web.1 | File "/Users/Yann/Documents/dev/choposcope/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load 
6:36:34 PM web.1 |  return self.load_wsgiapp() 
6:36:34 PM web.1 | File "/Users/Yann/Documents/dev/choposcope/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp 
6:36:34 PM web.1 |  return util.import_app(self.app_uri) 
6:36:34 PM web.1 | File "/Users/Yann/Documents/dev/choposcope/env/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app 
6:36:34 PM web.1 |  __import__(module) 
6:36:34 PM web.1 | ImportError: No module named wsgi 
6:36:34 PM web.1 | [2016-12-01 18:36:34 +0100] [9919] [INFO] Worker exiting (pid: 9919) 
6:36:34 PM web.1 | [2016-12-01 18:36:34 +0100] [9916] [INFO] Shutting down: Master 
6:36:34 PM web.1 | [2016-12-01 18:36:34 +0100] [9916] [INFO] Reason: Worker failed to boot. 
[DONE] Killing all processes with signal null 
6:36:34 PM web.1 Exited with exit code 3 

另外,我不知道如果wsgi模塊應該默認安裝在燒瓶上。當我嘗試在我的虛擬環境中運行pip install mod_wsgi,我得到這個錯誤:

pip install mod_wsgi 
Collecting mod_wsgi 
    Using cached mod_wsgi-4.5.9.tar.gz 
    Complete output from command python setup.py egg_info: 
    Traceback (most recent call last): 
     File "<string>", line 1, in <module> 
     File "/private/var/folders/_1/bhy3l2kj5l36_859j956y87m0000gn/T/pip-build-h3zlPa/mod-wsgi/setup.py", line 284, in <module> 
     APR_INCLUDES = get_apr_includes().split() 
     File "/private/var/folders/_1/bhy3l2kj5l36_859j956y87m0000gn/T/pip-build-h3zlPa/mod-wsgi/setup.py", line 245, in get_apr_includes 
     stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
     File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__ 
     errread, errwrite) 
     File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child 
     raise child_exception 
    OSError: [Errno 2] No such file or directory 

    ---------------------------------------- 
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/_1/bhy3l2kj5l36_859j956y87m0000gn/T/pip-build-h3zlPa/mod-wsgi/ 
+0

你是怎麼安裝heroku的? – daphtdazz

+0

不確定是什麼讓你覺得你需要Apache; Heroku完全不使用它,它在開發中肯定不是必需的。但是你們沒有給我們足夠的信息來回答這個問題。你的項目結構是什麼樣的?你在虛擬世界嗎?你安裝了哪些庫?你的proc文件是什麼?而且,最重要的是,* full *錯誤回溯是指什麼? –

+0

我添加了您要求的詳細信息。一切都在同一個文件夾中。 – ypicard

回答

2

從你給的命令行,gunicorn期待你已經稱爲文件:

choposcope/wsgi.py 

您不顯示如何設置您的目錄和文件的結構,但錯誤表明這樣的文件不存在。

雖然有一種方法可以在Heroku上安裝mod_wsgi-express,但我不會推薦它,因爲該機制並未得到主動支持。

如果您打算使用gunicorn進行本地開發以匹配Heroku上使用的內容,則不需要在那裏安裝mod_wsgi-express,儘管沒有理由不能使用mod_wsgi-express進行開發您希望作爲mod_wsgi-express(不是手動的Apache/mod_wsgi配置)對於本地開發來說與其他可用選項一樣簡單。

不知道你正在使用什麼文件系統結構,我猜你需要做的是將文件myapp.wsgi重命名爲wsgi.py。然後改變Procfile有:

web: gunicorn wsgi --log-file - 

wsgi參數是Python模塊名稱,因而文件爲什麼需要調用wsgi.py。當使用gunicorn時,它預計默認情況下WSGI應用程序入口點爲application。也許你可以也僥倖沒有wsgi.py文件和使用:

web: gunicorn choposcope:app --log-file - 

至於爲什麼,當你試圖在本地安裝pip install mod_wsgi失敗,這可能是由於是在MacOS X和不具有Xcode開發命令在線工具已安裝。或者你在HomeBrew中有一個破損或不完整的Apache httpd安裝。

+0

將名稱更改爲wsgi.py可以做到這一點。非常感謝你。 – ypicard

1

你不必下載它,你必須創建它。

文件的內容必須是:

from yourapplication import app as application 

欲瞭解更多信息,請參見瓶文檔:http://flask.pocoo.org/docs/0.11/deploying/mod_wsgi/#creating-a-wsgi-file

+0

錯誤已更改,但仍需要導入wsgi模塊。它應該在哪裏? 我不知道它是否應該默認安裝在瓶子上,但是如果我嘗試在我的虛擬環境中運行pip install mod_wsgi,它會失敗。我會將錯誤添加到帖子中。 – ypicard

相關問題