无法使用virtualenv运行Apache2

编程入门 行业动态 更新时间:2024-10-05 19:12:54
本文介绍了无法使用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 github/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 github/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.

  • modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html

简而言之,您需要卸载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.

  • pypi.python/pypi/mod_wsgi

更多推荐

无法使用virtualenv运行Apache2

本文发布于:2023-11-02 06:52:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551670.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:virtualenv

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!