Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have created a .py file and saved it in my "Python" folder located on my desktop. Now, I want to execute that particular file named "use.py".

How can I execute the file using LXTerminal?

share|improve this question
    
possible duplicate of run python in terminal –  Eliah Kagan Sep 10 at 0:38

1 Answer 1

You've got several options here (choose the one you like best):

  • Make the file itself executable.

    1. On the first line of the file, make sure the "shebang" is there:

      #!/usr/bin/env python
      

      This is needed for the shell so that it knows how to run the file.

    2. Mark the file executable on the filesystem:

      chmod +x thefile.py
      
    3. Run it like any other executable:

      ./thefile.py
      

      or

      /full/path/to/thefile.py
      
  • Run the file directly in the Python interpreter:

    python thefile.py
    

    The disadvantage of this is that everyone who would like to run the file should know how to call it. With the first option you have this inside the file itself and you can run the file without knowledge of that.

share|improve this answer
    
I think that the shebang way should be promoted over directly calling the interpreter. It's not that hard and is present in any script I write. –  minerz029 Oct 17 '13 at 12:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.