繁体   English   中英

mod_python忽略shebang并使用Python 2而不是3

[英]mod_python ignoring shebang and using Python 2 instead of 3

我正在尝试在浏览器中运行脚本。 我安装了mod_python以便在服务器上运行基于Web的应用程序,并在脚本中设置了一个shebang:

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import sys

def index():
    print ("Content-type: text/html\n")
    print('Version Python {0}'.format(sys.version_info[0]))

if __name__ == '__main__':
    index()

但是,当我从浏览器( 应用程序 )运行脚本时,我看到Python版本是2。当从控制台运行脚本时,使用:

python3 index.py

预期使用Python版本3.3.5。 为什么mod_python忽略了shebang?

UPD。 问题结案

  • 我选择退出mod_python。
  • 我在shebang中犯了一个错误(我应该为Unix设置\\ n行尾)。
  • 在PHP上编写用于运行python 3的包装器

在文件上设置可执行标志:

chmod a+x yourfile.py

然后,将其执行为:

./yourfile.py

使用shebang时,请按照以下步骤运行代码。

这使您的文件可执行

chmod +x index.py

这有助于您的代码执行

./index.py

暂无
暂无

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

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