简体   繁体   中英

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:

#!/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:

python3 index.py

Python version 3.3.5 is used as expected. Why is mod_python ignoring the shebang?

UPD. The Question closed

  • I opted out of the mod_python.
  • I founded a mistake in shebang (I should set \\n line endings for Unix).
  • Writed wrapper on php for running 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.

This makes your file executable

chmod +x index.py

This helps your code to execute

./index.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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