Python (beginner) - how do I get it running, starting from scratch?

orange123

New Member
Messages
3
Reaction score
0
Points
0
Hi,

I am trying to teach myself Python from scratch.
To even get started, I have spent the best part of 5 hours reading tutorials on the web, trying to figure out how to get even one line of Python running on my website. No luck.
So so far, I haven't even tested one line of code.

The tutorials show me how to write script, but (since they assume I am running the script on my PC) not how to get that script to run on my website.

How do I do this?

My file is called myfirstpage.py
Code:
 print 1 + 1
It's just one line, to at least get me started.

I put the file in the directory /cgi-bin/
I then tried to invoke the Python script from a html file, index.html:
Code:
 <html>
<head></head>
<body>
<a href="cgi-bin/myfirstpage.py">Click here to run Python script</a>
</body>
</html>
It doesn't work. When I click the link, it tells me I have a 500 Internal Server Error. Needless to say, I haven't a clue what I'm doing - and I can't teach myself if I can't get even one line to run!

I have looked on other threads.
This inspired me to add one line to my python page:
Code:
#!/usr/bin/python
print 1 + 1
but that didn't help.
Some of the advice given was
"Move file to cgi-bin directory and chmod it 755"

I don't know what 'chmod' means, so I have no idea what 'chmod it 755' means either. Can anyone help me and tell me what to do in layman's terms? :confused:

p.s. I'm a complete beginner, the only languages I know are html, xhtml, css and maybe 2 or 3 bits of php.

Thank you very much in advance!! :grouphug:
 

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
Just Googled it. Read through this site.
Some host providers only let you run CGI scripts in a certain directory, often named cgi-bin. In this case all you have to do to run the script is to call it like this:

http://my_server.tld/cgi-bin/my_script.py

The script will have to be made executable by "others". Give it a 755 permission or check the executable boxes if there is a graphical FTP interface.

To change the permissions (chmod) on x10, use the file manager on cpanel, check the box[es] for the file you wish to change, then press the "Change Permissions" icon (it looks like a key, with the text below it). You'll want to check everything except 'write' for group and world. At the bottom, it should say 755 if you do this correctly. If not, just randomly check and uncheck boxes until it says 755. :)
 
Last edited:

Jose Magsino

New Member
Messages
53
Reaction score
0
Points
0
page:
Code:
#!/usr/bin/python
print 1 + 1
but that didn't help.
Some of the advice given was
"Move file to cgi-bin directory and chmod it 755"

I don't know what 'chmod' means, so I have no idea what 'chmod it 755' means either. Can anyone help me and tell me what to do in layman's terms? :confused:

chmod means changing of file mode : when it is 755 .. that particularly, change the mode of your file to executable.

btw try changing your code to :
Code:
#!/usr/bin/python
print "Content-Type: text/html \r\n\r\n"
print 1 + 1

and changes also the mode of the file to executable as what Scoochi2 says in his reply to your post.

HTH.
 

orange123

New Member
Messages
3
Reaction score
0
Points
0
Thanks for the help. I use ftp instead of the file manager so I guess that's why I didn't see it, was pretty obvious really! The permissions were already on 755 though...
Does anyone else know how to get a basic python script working?
Thanks
 

bryanda

New Member
Messages
5
Reaction score
0
Points
0
This is able to work.

#!/usr/bin/python
#!/usr/bin/env python

print "Content-Type: text/html \r\n\r\n"
print "Hello, World!"
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Hi,

I am trying to teach myself Python from scratch.
To even get started, I have spent the best part of 5 hours reading tutorials on the web, trying to figure out how to get even one line of Python running on my website.
Don't do it that way. Seriously, don't. You'll have enough to worry about learning Python. You don't want to have to worry about Unix file permissions, CGI, HTTP &c. It's easy to install Python, and it's much easier to use the interactive shell than trying to debug a CGI script where the only error message you'll get is "500 internal server error".


I don't know what 'chmod' means, so I have no idea what 'chmod it 755' means either. Can anyone help me and tell me what to do in layman's terms?
If you want to be a programmer, you can't deal with technical matters in layman's terms. You need to learn how to read technical documents and think and speak rigorously. That doesn't mean you can't ask for clarity from documents and posts. Try zzee's Unix permissions tutorial, SiteGround's cPanel permissions tutorial and BuddingBlogger's tutorial on changing file permissions in FileZilla. FileZilla, if you haven't heard of it, is a wonderful FTP client.
 
Top