简体   繁体   English

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

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

I'm trying to run a script in the browser. 我正在尝试在浏览器中运行脚本。 I installed mod_python for running web-based applications on the server and set a shebang in my script: 我安装了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()

However, when I run my script from the browser ( my application ), I see that the Python version is 2. When I run the script from the console, using: 但是,当我从浏览器( 应用程序 )运行脚本时,我看到Python版本是2。当从控制台运行脚本时,使用:

python3 index.py

Python version 3.3.5 is used as expected. 预期使用Python版本3.3.5。 Why is mod_python ignoring the shebang? 为什么mod_python忽略了shebang?

UPD. UPD。 The Question closed 问题结案

  • I opted out of the mod_python. 我选择退出mod_python。
  • I founded a mistake in shebang (I should set \\n line endings for Unix). 我在shebang中犯了一个错误(我应该为Unix设置\\ n行尾)。
  • Writed wrapper on php for running python 3 在PHP上编写用于运行python 3的包装器

Set executable flag on the file: 在文件上设置可执行标志:

chmod a+x yourfile.py

Then, execute it as: 然后,将其执行为:

./yourfile.py

When shebang is used follow this steps to run the code. 使用shebang时,请按照以下步骤运行代码。

This makes your file executable 这使您的文件可执行

chmod +x index.py

This helps your code to execute 这有助于您的代码执行

./index.py

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

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