大网数据广告活动
服务器运维问答

How to change my Python version on CentOS for scripts executed via apache?

· 52CE 我爱测

I have a site say site.com/weather/a1.py When I try to execute this file, this shows the version of Python as 2.6 whereas If I execute it by logging into terminal via Putty it shows me the Python version as 3.6 Can some one educa…

问题原文

原帖链接 · Shan · CC BY-SA 3.0

I have a site say site.com/weather/a1.py

When I try to execute this file, this shows the version of Python as 2.6 whereas If I execute it by logging into terminal via Putty it shows me the Python version as 3.6

Can some one educate me on how to use Python3.6 for files executed via cgi-bin also?

Note : I recently changed my Python version using here

已采纳解答

原帖链接 · Vaibhav Panmand · CC BY-SA 3.0

You must have mod_wsgi apache module for 2.6 in apache that is why apache refer to older python version. You can install newer version of mod_wsgi using below commands.

Redhat / Centos

List available mod_wsgi versions

yum  list *mod_wsgi*

Select correct version and install with yum.

yum install python36u-mod_wsgi

Ubuntu

sudo apt-get -y install libapache2-mod-wsgi-py3

Reatsrt apache after successful installation, then it will load python version 3.x in apache configuration.

Specifically for CentOS

After doing above you need to do these also

1.Remove mod_python.so from apache httpd.conf 
2.python.conf might be available either in /etc/httpd/conf or /etc/http/conf.d
3.Comment out all the lines in it
4.Add WSGI alias as mentioned over [here][1]
5.Then restart apache

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-11-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。