1

Basically this is something that I had an issue with running C programme and I'm trying to run a python program from a terminal but the problem arises again. after tying an exact file in a exact directory the terminal doesn't seem to run the program and just skip it.

Is there something that I'm doing wrong to run and display on a terminal command?

$ ls
hello_world.py
$ python hello_world.py
$

This below 'script' is how I run the code with sublime text. Basically from my point of view there is no problem in script itself..

print('Hello Python world!')
  • 5
    Could you show the code inside `hello_world.py`? – bla Dec 25 '17 at 19:42
  • Did you look, if the process of this programm starts? And we need the code from hello_world.py – bierschi Dec 25 '17 at 19:43
  • I just edited and added the code and script. Basically I'm using sublime test editor. Is there something problem in script editor? –  Dec 25 '17 at 19:50
  • 4
    Whenever this kind of thing happens to me I am not running the same file I am changing. You can check it's content before running with `cat` for example. – bla Dec 25 '17 at 19:55
  • 1
    [Don't post pictures of code](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors), copy-paste the actual code and command line output instead. – Benjamin W. Dec 25 '17 at 20:56

3 Answers3

0

If your python is properly installed then there is no problem with the terminal. Python interpreter executes code line by line.It is completing the file and coming out of it.

vinayak
  • 34
  • 8
  • At least let us know what you are expecting as output – vinayak Dec 25 '17 at 19:51
  • 2
    I saw your edit now. Have you saved your file before compiling it ? – vinayak Dec 25 '17 at 19:53
  • Yes, I saved the file in a directory called 'python_work' in desktop and typed 'python hello_world.py' in terminal. Are there some setting required when using sublime text prior to downloading it? –  Dec 25 '17 at 20:07
0

Whenever I have this kind of problem it is because the file I'm trying to run is not the same I am changing. I recommend using something (like cat) to check the content of the file before actually running it.

So, in your case, pop up your terminal and run:

$ cat hello_world.py

The output should be

$ cat hello_world.py
print("Hello Python World!")

If the output is blank, there is your problem. Try to open that exact file with sublime. Probably with

$ sublime hello_world.py
bla
  • 1,840
  • 1
  • 13
  • 17
-4

At the top of your .py file

Add

#!/usr/bin/python3 

Then when you need to give your file permissions

chmod +x hello_world.py

Then to run

./hello_world.py

This will run it in python3 if you want python2 just change that in the usr/bin