簡體   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