0

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
Artem Chernov
  • 856
  • 2
  • 8
  • 26
  • Can you show the starting few lines of the entire code? And are you running this in linux? – Anand S Kumar Sep 21 '15 at 10:27
  • @AnandSKumar i add entire script in my question, i use CentOS – Artem Chernov Sep 21 '15 at 10:32
  • @jonrsharpe if i run script ./myscriptname.py raise error No such file or directory – Artem Chernov Sep 21 '15 at 10:35
  • @jonrsharpe i send request to server from my browser. [My script](http://myautobest.ru/check-robots/index.py) – Artem Chernov Sep 21 '15 at 10:39
  • I think OP wants to embed python3 code in html and run it. – kmario23 Sep 21 '15 at 10:57
  • @kmario23 My application writed on python. And now I created API for them. Therefore i configure a server for run python not only from console – Artem Chernov Sep 21 '15 at 11:06
  • 1
    This is an issue with how mod_python was installed. See http://modpython.org/live/current/doc-html/installation.html#running-configure for instructions if you installed mod_python yourself. If you had a package manager install it you'll need to look at their documentation. I'm voting to close and move this to ServerFault. – robert Sep 21 '15 at 13:41

2 Answers2

1

Set executable flag on the file:

chmod a+x yourfile.py

Then, execute it as:

./yourfile.py
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
0

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
trishnag
  • 182
  • 1
  • 3
  • 13