-3

I am new to Linux and python. I downloaded a .py file I am trying to "run" it. I did "./ filename" every time I do that it opens a gedit screen showing me all the innards(code) of the file.

PLC
  • 3
  • 1
  • 3

1 Answers1

0

Python is a scripting language, so it needs an interpreter in order to 'execute' the script.

To execute the script can be done via the shebang. To use the shebang you must make the file executable:

$ chmod +x your-script.py

Then you can call it normally from your command line:

$ ./your-script.py

or calling the interpreter 'manually':

$ python your-script.py

I'm assuming the script is in the current directory

Community
  • 1
  • 1
Esparta Palma
  • 695
  • 5
  • 9
  • the file has a shebang in it already. That's why I'm so confused. Is this "interpreter" something I need to download from somewhere? – PLC Apr 06 '15 at 20:12
  • #!/usr/bin/python import import sys import dbus import uuid import urllib2 import httplib import getpass these are the first 10 lines of the file...also this site is awesome I did not think someone would responded...especially that quick. – PLC Apr 06 '15 at 20:13
  • your linux machine has the python interpreter included. In the command line try this: python -c "print 'Hello World'" – Esparta Palma Apr 06 '15 at 20:14
  • the terminal went into this ">" and does not respond to "quit()" "end" "kill" or anything else. I just do not understand why when I "run" the program it does not pop up as it would on a mac or pc. This gedit showing the code but it doesnt actually "RUN" the program. – PLC Apr 06 '15 at 20:22
  • If your terminal went to ">" is because is still interpreting and waiting for something, perhaps you missed the second double-quote. Copy-paste exactly all the command: python -c "print 'Hello World'" To properly exit the interpreter you should hit ctrl+D. – Esparta Palma Apr 06 '15 at 20:27
  • Yes, Thank you. So what happened is that is spit out Hello World. and went back to the normal shell beginning line. – PLC Apr 06 '15 at 20:30
  • Any idea on why the .py file Idown loaded will not ( or I don't know how to ) "run" also is that even the right terminology In mac I double click something I have downloaded and it opens a dmg...then i click the dms to "run" this program. how do I do that here? – PLC Apr 06 '15 at 20:32
  • Your question was about how to run your script. Did my answer work? What did happened? The problem on how your linux GUI associate your python scripts is a completely different issue, Stack Overflow is about precise questions not a broad online tutorial/forum to solve all your questions. See this, please: http://stackoverflow.com/tour – Esparta Palma Apr 06 '15 at 20:38
  • I thought my question was pretty specific. How can I get my "script" to work. I have done all of what you said before I asked the question. S.O was my last opinion. I repeated these step when you mentioned them. The exact same thing happens. It opens a "getit" window only showing the code...it never actually does what it is supposed to do. – PLC Apr 06 '15 at 20:43
  • Edit your original question adding all the steps (and screnshots) on what you are doing and what happen if you did one or another thing. If this is posible give more information on what your trying to do, the url of the script. Is impossible to us to figure out what is happening in your machine without exact steps to reproduce and your current configuration. – Esparta Palma Apr 06 '15 at 20:48
  • I figured it out. Thank you I really appropriate I found a Youtube video barried on the net about my issue. Also How can I get my question back to "0" The downvoter says that it already had an answer but in fact, this was not the case. – PLC Apr 06 '15 at 20:51