Need help with python and geany

Okay, so I decided it is about time I actually tried to learn some proper programming on Linux as it is pretty embarrassing I have not yet done so.

To that end, I have read that python is a good place for beginners to start and so that is what I am starting out with. I have installed Geany and have opened a new file with a python template which is:

main.py

I have added the single line of code:

print("Hello, World!")

I have then saved the file and then hit the “compile the current program” button. I have then hit the “run or view the current file” button. But, in the terminal, I get this error:

------------------

(program exited with code: 0)
Press return to continue

What am I doing wrong?

FYI - I am using Ubuntu 16.04 64 bit and Geany 1.27

I dont think your doing anything wrong.
Its just telling you that the program has ended with no errors.

here’s my code :-

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  myMain.py

def main(args):
	
    return 0

print("Hello, World!")
if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))

Exit code 0 indicates the program closed with no problems, so it might be issuing the wrong command to run your Python script.

You could alternately run it in the regular terminal, providing the file is "marked as executable":

/path/to/main.py

For a simple print command, it should output that text.


If you check Build → Set build commands... from the menu bar, the execute command should read this:

Python is an interpreted language, so it doesn't need compiling. You can run the script by pressing F5 or by pressing Execute.


Also, for good measure, ensure the Python script starts with the shebang as the first line in the script:

#!/usr/bin/env python

Or if it's Python3 code:

#!/usr/bin/python3
1 Like

I have run the code provided by you Cybermnax power and hit F5, but get the same error. I have then opened up the set build command dialog box and it reads different to what you have shown Lah7.

Please see below:

Ok…update

It works with just:

print("Hello, World!")

as a single line of code and nothing else in there

so, that’s a start…:slight_smile:

2 Likes

Hi @stevecook172001,

I’m not sure if you have read something like this but it looks like a good place to start?:

Line 33 and 34 in that video are supposed to be lines 1 and 2.

I'm not sure using geany is doing you any favor if you're looking to get some basic Python programming skills.

You can just use pluma to create a file prog.py on your desktop containing:

#! /usr/bin/env python
# coding: utf-8

print "Hello world!"

Then run it using python Desktop/prog.py

If you want to make it an executable program: chmod +x Desktop/prog.py and then execute using ./Desktop/prog.py

2 Likes

There is an excellent course for beginners in Python @ https://www.coursera.org/learn/learn-to-program