By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

Hi All, have a question

P: n/a
Hi, I'm still a relative Python newbie, though I am learning more with every
project:) I have a script I wrote to back up a Linux server to another
server. The script is centered around the OS module. Problem is, then I put
the #!/usr/bin/python in the front and try to run it as a executable, it
comes up and tells me the module can't be imported, and the rest goes
straight to hell from there. Thing is, if I run the script with the
interpreter manually (IE, python backup.py) it runs just fine. On the other
two servers, it works just like it should, I type back up and it runs. Does
anyone have any ideas where I need to start looking?

Thanks in advance,

Paul
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Wed, 11 Feb 2004 15:08:21 -0600, Paul Metzger wrote:
Hi, I'm still a relative Python newbie, though I am learning more with every
project:)
Glad you're charging ahead with your learning.
I put
the #!/usr/bin/python in the front
Presumably you mean this was placed on the first line.

To make your script a little more portable, the shebang line should be:

#!/usr/bin/env python

This will execute the "python" command from wherever it resides,
presuming it is in the user's execution PATH environment variable.
try to run it as a executable, it comes up and tells me the module
can't be imported


Please show the exact command you're typing, and the exact error
message.
To make a script that can be imported as a module *and* executed as a
script, put the "do this stuff when run as a script" at the end in the
following conditional block:

if ( __name__ == '__main__' ):
# do the main purpose of this script

More here:

<http://www.python.org/doc/current/lib/module-main.html>

--
\ "I installed a skylight in my apartment. The people who live |
`\ above me are furious!" -- Steven Wright |
_o__) |
Ben Finney <http://bignose.squidly.org/>
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.