繁体   English   中英

无法使用virtualenv运行Apache2

[英]Can't run Apache2 with virtualenv

我正在建立一个基于Django的网站,服务器上安装了Python 3.5,但是我的项目需要Python 3.6。 我决定使用virtualenv。 我已经成功安装了所需版本的Python,但无法使用virtualenv使它与Apatche2一起使用。

网站只能在Python 2.7上运行,否则什么也没有发生,页面已加载很长时间,没有任何错误。

这是我的VirtualHost配置,我尝试在Python 3.6上运行。

<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]

我可以通过这种方式获得的唯一一件事(在删除WSGIDaemonProcessWSGIProcessGroup同时)是:

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.gz
tar -xf 4.6.3.tar.gz
./configure --with-python=/usr/local/bin/python3.6
make
make install
现在一切正常。
感谢@Graham Dumpleton,您的回答很有帮助。

mod_wsgi模块是链接到Python库的C代码。 因此,将为其编译的Python版本嵌入到模块中。 它不仅执行python程序。 这意味着它必须针对您要使用的Python版本进行编译。 您不能通过虚拟环境强制其使用其他Python版本。 有关在虚拟环境中使用mod_wsgi的文档中对此进行了说明。

简而言之,您需要卸载mod_wsgi模块(可能是操作系统打包的模块),并从源代码中自己安装mod_wsgi,并针对您要使用的Python版本进行编译。 最简单的方法是使用pip install方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM