无法使用virtualenv运行Apache2 [英] Can't run Apache2 with virtualenv

查看:53
本文介绍了无法使用virtualenv运行Apache2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

I'm making a website based on Django, on the server was installed a Python 3.5, but my project requires a Python 3.6. I decided to use virtualenv. I successfuly installed needed version of Python but I can't make it works with Apatche2 using virtualenv.

Website is able to run only on Python 2.7, otherwise nothing happens, page is loading for a long time without any error.

Here is my VirtualHost config with my try to run on 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]

我能以这种方式获得的唯一一件事(同时删除 WSGIDaemonProcess WSGIProcessGroup 时)是:

Only one thing what I can get this way (while WSGIDaemonProcess and WSGIProcessGroup is deleted) is:

2.7.13(默认值,2017年11月24日,17:33:09)[GCC 6.3.0 20170516]

2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]

有一种可能是我缺少软件包,因为我重新安装了python 3.5,需要哪些软件包才能工作?

Edit 1:

There is a posiblity I have missing packages, bacause I made reinstalation of python 3.5, what are required packages to work?

我做了两件事,我不确定到底有什么帮助,但是首先我禁用了mod( a2dismod wsgi )并删除了一个软件包 libapache2-mod-wsgi .

I did two things, I'm not sure what exacly help me but first of all I disabled a mod (a2dismod wsgi) and deleted a package libapache2-mod-wsgi.

apt-get install libapache2-mod-wsgi-py3

我从源代码安装了 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
进行安装
现在一切正常.
感谢@Graham Dumpleton,您的回答很有帮助.

I installed a mod-wsgi from the source:
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
Now everything works perfectly.
Thanks @Graham Dumpleton, your answer was helpful.

推荐答案

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

The mod_wsgi module is C code which links to the Python library. Thus the version of Python it is compiled for is embedded in the module. It doesn't just execute python program. This means it has to be compiled for the version of Python you want to use. You cannot force it via a virtual environment to use a different Python version. This is stated in the documentation on using mod_wsgi with virtual environments.

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

In short, you need to uninstall the mod_wsgi module (likely the operating system packaged one), and install mod_wsgi yourself from source code, compiling it against the Python version you want to use. Easiest way of doing that is to use pip install method.

这篇关于无法使用virtualenv运行Apache2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆