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
7
  • Can you show the starting few lines of the entire code? And are you running this in linux? Commented Sep 21, 2015 at 10:27
  • @AnandSKumar i add entire script in my question, i use CentOS Commented Sep 21, 2015 at 10:32
  • @jonrsharpe if i run script <code>./myscriptname.py</code> raise error <code>No such file or directory</code> Commented Sep 21, 2015 at 10:35
  • @jonrsharpe i send request to server from my browser. My script Commented Sep 21, 2015 at 10:39
  • 1
    This is an issue with how mod_python was installed. See modpython.org/live/current/doc-html/… 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. Commented Sep 21, 2015 at 13:41

2 Answers 2

1

Set executable flag on the file:

chmod a+x yourfile.py

Then, execute it as:

./yourfile.py
Sign up to request clarification or add additional context in comments.

2 Comments

Although correct in the general sense, I'm not sure this helps the OP with whatever they mean by "from browser".
@LeoKomarov then provide enough information, otherwise you'll never get an answer
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.