【发布时间】:2018-09-04 19:56:03
【问题描述】:
我正在制作一个基于 Django 的网站,服务器上安装了 Python 3.5,但我的项目需要 Python 3.6。我决定使用 virtualenv。我成功安装了所需的 Python 版本,但无法使用 virtualenv 使其与 Apatche2 一起使用。
网站只能在 Python 2.7 上运行,否则什么都不会发生,页面加载很长时间没有任何错误。
这是我尝试在 Python 3.6 上运行的 VirtualHost 配置。
<VirtualHost *:443>
ServerName <site_adress>:443
ServerAdmin admin@<site_adress>
DocumentRoot /var/www/html/MMServer
ErrorLog /var/www/logs/error.log
CustomLog /var/www/logs/custom.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/mm.cert
SSLCertificateKeyFile /etc/apache2/ssl/mm.key
Alias /static/ /var/www/html/MMServer/static/
<Directory /var/www/html/MMServer/static>
Require all granted
</Directory>
WSGIDaemonProcess MMServer python-path=/var/www/html/MMServer python-home=/var/www/html/venv
WSGIProcessGroup MMServer
WSGIScriptAlias / /var/www/html/MMServer/mm_server/wsgi.py
<Directory /var/www/html/MMServer/mm_server>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
下面是我的wsgi.py文件:
import os
import sys
def application(environ, start_response):
start_response('200 OK',[('Content-type','text/html')])
return [sys.version]
我能通过这种方式得到的只有一件事(WSGIDaemonProcess 和 WSGIProcessGroup 被删除)是:
2.7.13(默认,2017 年 11 月 24 日,17:33:09)[GCC 6.3.0 20170516]
编辑 1:
有可能我缺少软件包,因为我重新安装了 python 3.5,需要哪些软件包才能工作?
解决方案:
我做了两件事,我不确定什么对我有帮助,但首先我禁用了一个 mod (a2dismod wsgi) 并删除了一个包 libapache2-mod-wsgi。
选项 1:
apt-get install libapache2-mod-wsgi-py3
选项 2:
我从源安装了mod-wsgi:wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.6.3.tar.gztar -xf 4.6.3.tar.gz./configure --with-python=/usr/local/bin/python3.6makemake install
现在一切正常。
谢谢@Graham Dumpleton,你的回答很有帮助。
【问题讨论】:
-
谢谢。这对我有用。这需要记录在 Django 官方网站上。
标签: python django apache virtualenv mod-wsgi