[英]Using Anaconda python with mod_wsgi
我正在嘗試將我的Apache服務器設置為在使用mod_wsgi時使用Anaconda python而不是系統python。
這是我的Apache配置文件:
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /opt/anaconda/bin
WSGIPythonPath /opt/anaconda/bin:/opt/anaconda/pkgs
一旦我啟動服務器,我的錯誤日志就會充斥着
ImportError: No module named site
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
mod_wsgi是版本4.4.12並使用與我的anaconda安裝(2.7.10)相同的python版本編譯。
我究竟做錯了什么? 如何設置我的Apache配置文件以從非默認位置運行python?
看起來你的Python路徑設置不正確。 進入你的Anaconda python並輸入:
import site
site
應顯示站點模塊的目錄。 它應該是這樣的: python_path/lib/site.pyc
將Apache配置更改為:
WSGIPythonPath python_path:python_path/lib/site-packages
其中python_path
是您在導入site
時找到的內容。
我遲到了,但我遇到了同樣的問題。 為了澄清@Ringil的解決方案,我使用系統安裝的mod_wsgi在我的VirtualHost配置中包含了類似的內容:
WSGIDaemonProcess mysite python-path=/path/to/anaconda2/lib/python2.7/site-packages
請注意,正如@Ringil指出的那樣, site-packages
目錄需要在PYTHONPATH
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.