2017-03-01 104 views
1

我使用Ubuntu和Apache運行服務器。現在我正在嘗試使用mod_wsgi來處理Anaconda,但卻無法讓它工作。Anaconda + Apache + mod_wsgi + Ubuntu

首先。如果我使用mod_wsgi-express,它正在工作。通過遵循https://anaconda.org/pypi/mod_wsgi中的安裝到Python中的說明,我可以通過首先設置PYTHONHOME=/opt/anaconda然後/opt/anaconda3/bin/mod_wsgi-express start-server來實現它。

我想使用Apache,因此我將mod_wsgi模塊從anaconda加載到apache中。然後,我有一個虛擬主機看起來像這樣:

WSGIPythonHome /opt/anaconda3 
WSGIPythonPath /opt/anaconda3/lib/python3.6/site-packages:/path/to/application 
<VirtualHost *:8080> 
ServerName example.com 
WSGIDaemonProcess example python-home=/opt/anaconda3 python-path=path/to/application:/opt/anaconda3/lib/python3.6/site-packages 
WSGIProcessGroup example 

WSGIScriptAlias//path/to/application/wsgi.py 

<Directory /path/to/application/static> 
    Require all granted 
</Directory> 

<Directory /path/to/application> 
<Files wsgi.py> 
    Require all granted 
</Files> 
</Directory> 

</VirtualHost> 

現在的問題。我在我的apache錯誤日誌中得到這個錯誤。如果我沒有用mod_wsgi_express指定PYTHONHOME=/opt/anaconda,我會得到同樣的錯誤。

[Wed Mar 01 09:31:17.159233 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19356 (gen 0/slot 1) started 
[Wed Mar 01 09:31:17.159638 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19357 (gen 0/slot 2) started 
[Wed Mar 01 09:31:17.160049 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19358 (gen 0/slot 6) started 
[Wed Mar 01 09:31:17.160467 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19359 (gen 0/slot 7) started 
[Wed Mar 01 09:31:17.160967 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19360 (gen 0/slot 8) started 
[Wed Mar 01 09:31:17.161421 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19361 (gen 0/slot 9) started 
[Wed Mar 01 09:31:17.161877 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19362 (gen 0/slot 10) started 
[Wed Mar 01 09:31:17.162345 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19363 (gen 0/slot 11) started 
[Wed Mar 01 09:31:17.162792 2017] [wsgi:info] [pid 19361] mod_wsgi (pid=19361): Python home /opt/anaconda3. 
[Wed Mar 01 09:31:17.162817 2017] [wsgi:info] [pid 19361] mod_wsgi (pid=19361): Initializing Python. 
[Wed Mar 01 09:31:17.166761 2017] [wsgi:info] [pid 19362] mod_wsgi (pid=19362): Python home /opt/anaconda3. 
[Wed Mar 01 09:31:17.166806 2017] [wsgi:info] [pid 19362] mod_wsgi (pid=19362): Initializing Python. 
[Wed Mar 01 09:31:17.170927 2017] [wsgi:info] [pid 19360] mod_wsgi (pid=19360): Python home /opt/anaconda3. 
[Wed Mar 01 09:31:17.170967 2017] [wsgi:info] [pid 19360] mod_wsgi (pid=19360): Initializing Python. 
[Wed Mar 01 09:31:17.174897 2017] [wsgi:info] [pid 19359] mod_wsgi (pid=19359): Python home /opt/anaconda3. 
[Wed Mar 01 09:31:17.174921 2017] [wsgi:info] [pid 19359] mod_wsgi (pid=19359): Initializing Python. 
[Wed Mar 01 09:31:17.178746 2017] [wsgi:info] [pid 19363] mod_wsgi (pid=19363): Python home /opt/anaconda3. 
[Wed Mar 01 09:31:17.178769 2017] [wsgi:info] [pid 19363] mod_wsgi (pid=19363): Initializing Python. 
[Wed Mar 01 09:31:17.182570 2017] [core:notice] [pid 16941] AH00052: child pid 19317 exit signal Aborted (6) 
[Wed Mar 01 09:31:17.182582 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19317 (gen 0/slot 0) exited 
[Wed Mar 01 09:31:17.182594 2017] [core:notice] [pid 16941] AH00052: child pid 19318 exit signal Aborted (6) 
[Wed Mar 01 09:31:17.182597 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19318 (gen 0/slot 3) exited 
[Wed Mar 01 09:31:17.182605 2017] [core:notice] [pid 16941] AH00052: child pid 19319 exit signal Aborted (6) 
[Wed Mar 01 09:31:17.182608 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19319 (gen 0/slot 4) exited 
[Wed Mar 01 09:31:17.182615 2017] [core:notice] [pid 16941] AH00052: child pid 19320 exit signal Aborted (6) 
[Wed Mar 01 09:31:17.182618 2017] [core:trace4] [pid 16941] mpm_common.c(530): mpm child 19320 (gen 0/slot 5) exited 
[Wed Mar 01 09:31:17.182636 2017] [wsgi:info] [pid 16941] mod_wsgi (pid=19321): Process 'store-test' has died but server is being stopped, deregister it. 
[Wed Mar 01 09:31:17.182646 2017] [wsgi:info] [pid 16941] mod_wsgi (pid=19321): Process 'store-test' has been deregistered and will no longer be monitored. 
[Wed Mar 01 09:31:17.182934 2017] [wsgi:info] [pid 19358] mod_wsgi (pid=19358): Python home /opt/anaconda3. 
[Wed Mar 01 09:31:17.182954 2017] [wsgi:info] [pid 19358] mod_wsgi (pid=19358): Initializing Python. 
[Wed Mar 01 09:31:17.186756 2017] [wsgi:info] [pid 19357] mod_wsgi (pid=19357): Python home /opt/anaconda3. 
[Wed Mar 01 09:31:17.186781 2017] [wsgi:info] [pid 19357] mod_wsgi (pid=19357): Initializing Python. 
[Wed Mar 01 09:31:17.190807 2017] [wsgi:info] [pid 19356] mod_wsgi (pid=19356): Python home /opt/anaconda3. 
[Wed Mar 01 09:31:17.190840 2017] [wsgi:info] [pid 19356] mod_wsgi (pid=19356): Initializing Python. 
Could not find platform independent libraries <prefix> 
Could not find platform dependent libraries <exec_prefix> 
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] 
Fatal Python error: Py_Initialize: Unable to get the locale encoding 
ModuleNotFoundError: No module named 'encodings' 
Current thread 0x00007f4ad9333780 (most recent call first): 

任何人都知道我能做些什麼來使它工作?

回答

2

如果您想要使用Anaconda Python,則不能使用任何系統軟件包作爲mod_wsgi。所以第一步是卸載任何系統的mod_wsgi包。

然後使用pip install mod_wsgimod_wsgi-express安裝到您的Anaconda Python安裝或虛擬環境中。

然後運行:

mod_wsgi-express module-config 

取的輸出,並把它變成你的Apache配置文件加載的mod_wsgi。

然後添加到Apache爲您的特定WSGI應用程序的mod_wsgi配置。

如果遇到問題,請在顯示您正在使用的配置後進行。

+0

謝謝你的幫助。我用Anacondas pip來安裝_mod_wsgi_。我已經將_mod_wsgi_加載到apache中,並從apache配置中刪除了所有其他的。由於_module-config_不是有效的命令,我不能執行'mod_wsgi-express module-config'。有效的命令是_install-module,module-location,setup-server和start-server_。其中沒有一個創建了用於Apache的輸出。如果我使用_start-server_,我可以閱讀它使用的apache配置,但它不能幫助我解決問題。它使用的配置也要求我設置'PYTHONHOME'。 –

+0

你很早以前就必須做一個mod_wsgi的pip安裝,並且有一箇舊版本。做一個''pip uninstall mod_wsgi'',然後重新安裝它。 –

+0

我已經試過,沒有任何結果。但是遺忘了一些事情是非常錯誤的。我試圖在新鮮的Ubuntu安裝中安裝anaconda,並且在那裏工作正常。這是我的同事在錯誤的安裝上安裝了anaconda,他可能以某種方式破壞了它。謝謝! –