这是我的应用程序的apache配置
WSGIPythonPath /var/djp/myapp:/root/.virtualenvs/myapp/lib/python2.7/site-packages
<VirtualHost *:80>
WSGIDaemonProcess mydomain.com python-path=/var/djp/myapp:/root/.virtualenvs/myenv/lib/python2.7/site-packages
WSGIProcessGroup mydomain.com
WSGIPassAuthorization On
WSGIScriptAlias / /var/djp/myapp/myapp/wsgi.py
ServerName mydomain.com
ServerAlias *.mydomain.com
ErrorLog ${APACHE_LOG_DIR}/myapp/myapp_error.log
LogLevel info
</VirtualHost>
如果然后我切换到myenv并检查python中的版本我得到
>>> import django
>>> django.VERSION
(1, 9, 7, 'final', 0)
>>> import sys
>>> print sys.path
*the path is ok*
但是,如果我打开我的应用程序的网页,我会看到以下
Django Version: 1.8.3
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/var/djp/myapp', # - ok
'/root/.virtualenvs/myenv/lib/python2.7/site-packages', # - ok
'/usr/lib/python2.7', # - not ok (global)
'/usr/lib/python2.7/plat-linux2', # - not ok (global)
'/usr/lib/python2.7/lib-tk', # - not ok (global)
'/usr/lib/python2.7/lib-old', # - not ok (global)
'/usr/lib/python2.7/lib-dynload', # - not ok (global)
'/usr/local/lib/python2.7/dist-packages', # - not ok (global)
'/usr/lib/python2.7/dist-packages', # - not ok (global)
'/usr/lib/python2.7/dist-packages/PIL', # - not ok (global)
'/usr/lib/pymodules/python2.7']
我只是不明白,为什么它首先执行django 1.8?应首先找到我的本地站点包。我的第一个想法是,python在myenv中找不到django 1.9。但我可以轻松地从python shell导入它,如上所示!
以下是myenv中pip冻结的输出:
Django==1.9.7
argparse==1.2.1
distribute==0.6.24
django-crispy-forms==1.6.0
djangorestframework==3.3.3
psycopg2==2.6.1
wsgiref==0.1.2
一切都在它的位置。我不知道会发生什么。请帮忙
答案 0 :(得分:1)
尝试:
WSGIRestrictEmbedded On
<VirtualHost *:80>
WSGIDaemonProcess mydomain.com python-home=/root/.virtualenvs/myenv python-path=/var/djp/myapp
WSGIProcessGroup mydomain.com
WSGIPassAuthorization On
WSGIScriptAlias / /var/djp/myapp/myapp/wsgi.py
ServerName mydomain.com
ServerAlias *.mydomain.com
ErrorLog ${APACHE_LOG_DIR}/myapp/myapp_error.log
LogLevel info
</VirtualHost>
也就是说,在嵌入模式进程中关闭解释器初始化,然后使用python-home
选项来说明虚拟环境的位置。
剩下的问题是您是否使用非系统Python安装。如果你和mod_wsgi实际上是为系统Python而不是你的单独编译的,那么还需要做更多的工作。
另一个问题可能是/root
目录实际上对Apache用户不可读。