Python scripts wont run - HELP

W

windozbloz

Bye Bye Billy Bob...

Hello All,
I'm a fairly literate windoz amateur programmer mostly in visual basic. I
have switched to SuSE 9.2 Pro and am trying to quickly come up to speed
with Python 2.3.4. I can run three or four line scripts from the command
line but have not been able to execute a script from a file.

I have used EMACS and JEDIT to create small test routines. I would right
click the file and set properties to executable. I would then click the
icon, the bouncy ball would do its thing then a dialog box would flash on
the screen for a fraction of a second. I could tell it had a progress bar
on it but could not catch anything else on it. Then nothing else would
happen.

If I could execute a script the world would once again be my playground...
PLEASE HELP.
 
J

John Abel

windozbloz said:
Bye Bye Billy Bob...

Hello All,
I'm a fairly literate windoz amateur programmer mostly in visual basic. I
have switched to SuSE 9.2 Pro and am trying to quickly come up to speed
with Python 2.3.4. I can run three or four line scripts from the command
line but have not been able to execute a script from a file.

I have used EMACS and JEDIT to create small test routines. I would right
click the file and set properties to executable. I would then click the
icon, the bouncy ball would do its thing then a dialog box would flash on
the screen for a fraction of a second. I could tell it had a progress bar
on it but could not catch anything else on it. Then nothing else would
happen.

If I could execute a script the world would once again be my playground...
PLEASE HELP.
You will need to include

#!/usr/bin/python

At the top of your script.

HTH

J
 
D

Damjan

I'm a fairly literate windoz amateur programmer mostly in visual basic. I
have switched to SuSE 9.2 Pro and am trying to quickly come up to speed
with Python 2.3.4. I can run three or four line scripts from the command
line but have not been able to execute a script from a file.

I have used EMACS and JEDIT to create small test routines. I would right
click the file and set properties to executable. I would then click the
icon, the bouncy ball would do its thing then a dialog box would flash on
the screen for a fraction of a second. I could tell it had a progress bar
on it but could not catch anything else on it. Then nothing else would
happen.

If I could execute a script the world would once again be my playground...
PLEASE HELP.

Open a terminal program like "konsole".
change the directory to where your files are ("cd /path/to/files/").
execute them ("python my-script.py').
 
W

windozbloz

Damjan said:
Open a terminal program like "konsole".
change the directory to where your files are ("cd /path/to/files/").
execute them ("python my-script.py').
THANK YOU THANK YOU THANK YOU
It now works from the command line like you said. Shouldn't I also be able
to 'click' an icon that has been set to executable and launch the whole
process that way?

Doug
 
N

Nick Vargish

windozbloz said:
It now works from the command line like you said. Shouldn't I also be able
to 'click' an icon that has been set to executable and launch the whole
process that way?

You'll need to put an interpreter line at the beginning of your
script, as other posters have indicated. This tells the shell how to
handle the file.

When you double-click a program icon in your file browser, the browser
starts a shell process which is handed the file's name for
execution.

#!/usr/bin/python

Says, "This file is interpreted by /usr/bin/python". The idiom you
will often see:

#!/usr/bin/env python

Says, "Find 'python' in this user's environment, and give this file to
that program for interpretation". That allows you to use a different
python interpreter (say, /usr/local/bin/python if that comes first on
your PATH environment variable), and allows the script to be more
friendly for systems that do not have a /usr/bin/python.

Depending on the GUI, you may not see a terminal window open for the
script's execution, or the terminal might close as soon as the script
exits, which will prevent you from looking at any output. Unless the
program has a GUI, running it from the command-line is usually better
than double-clicking it in a file browser.

Nick
 
W

windozbloz

Nick said:
You'll need to put an interpreter line at the beginning of your
script, as other posters have indicated. This tells the shell how to
handle the file.

When you double-click a program icon in your file browser, the browser
starts a shell process which is handed the file's name for
execution.

#!/usr/bin/python

Says, "This file is interpreted by /usr/bin/python". The idiom you
will often see:

#!/usr/bin/env python

Says, "Find 'python' in this user's environment, and give this file to
that program for interpretation". That allows you to use a different
python interpreter (say, /usr/local/bin/python if that comes first on
your PATH environment variable), and allows the script to be more
friendly for systems that do not have a /usr/bin/python.

Depending on the GUI, you may not see a terminal window open for the
script's execution, or the terminal might close as soon as the script
exits, which will prevent you from looking at any output. Unless the
program has a GUI, running it from the command-line is usually better
than double-clicking it in a file browser.

Nick
Thats good info Nick, Thanks. I'm going to go try the two methods now.
Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,261
Messages
2,571,308
Members
47,976
Latest member
AlanaKeech

Latest Threads

Top