Issue
I have a hello.py file located in "/home/user1/public_html/cgi-bin" that displays the python version:
#!/usr/bin/python
import platform
print "Content-type: text/html\n\n"
print(platform.python_version())
When I go to the url for the script, it displays "2.6.6" in the browser.
I am wanting to use python 3.5 so I had the webhost install a virtualenv in "/home/user1/virtualenv/testproject/"
When I try to change the first line of the code to:
#!/home/user1/virtualenv/testproject/3.5/bin/python
import platform
print "Content-type: text/html\n\n"
print(platform.python_version())
the script will display "It works! Python 3.5.5" which is not what I have coded into the script.
Am I supposed to put the hello.py file into the virtualenv directory? Or is it that I have the path to the python 3.5 incorrect? Or am I just totally misunderstanding how all of this works? Any help would be appreciated.
Solution
phd's comment was the correct answer. print
is a function in Python 3, so you must call it: print("Content-type: text/html\n\n")
. print-as-operator is a SyntaxError in Python 3.
Answered By - krazyboi Answer Checked By - Clifford M. (WPSolving Volunteer)