Permission Denied

T

Tom Strickland

Hopefully this is a simple question. I've started to program in Python
after an absence of about a year, so I'm very rusty. I wrote a short
program and tried to run it using Python2.4 in Linux. I keep getting
"permission denied" messages after entering the path to the program. I
switched to the root directory and tried again, but got the same
result.I ran a very similar program earlier and it ran fine.

What am I doing wrong? The program is:


#!/usr/bin/python2.4
i=1
while i<10000:
print 'step 1',i
i+=1
raw_input()
print 'step 2'


Thank you.

Tom
 
H

hiaips

Tom said:
Hopefully this is a simple question. I've started to program in Python
after an absence of about a year, so I'm very rusty. I wrote a short
program and tried to run it using Python2.4 in Linux. I keep getting
"permission denied" messages after entering the path to the program. I
switched to the root directory and tried again, but got the same
result.I ran a very similar program earlier and it ran fine.

What am I doing wrong? The program is:


#!/usr/bin/python2.4
i=1
while i<10000:
print 'step 1',i
i+=1
raw_input()
print 'step 2'


Thank you.

Tom


Is your script executable?
 
A

AlbaClause

hiaips said:
Is your script executable?

That's the problem I had when I wrote my first Python script. I wrote it
using vi, and vi doesn't save files with the executable flag set. A simple
'chmod 755 script.py' fixed that right up.

Then, to execute the file from from the shell prompt, I had to create a
'bin' directory in my home folder, cuz I didn't want to litter
my /usr/local/bin folder with useless Python scripts. (Useless because I
wrote them to learn the language and for no other practical purpose.) Of
course, I had to uncomment a line or two in my .bashrc file too.

Hey, what do I know? I'm as new to this as virgins are to... Well, you get
the idea. :p


--
 
L

Lawrence D'Oliveiro

Then, to execute the file from from the shell prompt, I had to create a
'bin' directory in my home folder, cuz I didn't want to litter
my /usr/local/bin folder with useless Python scripts.

Executable files can be kept anywhere, you don't need a special directory
for them.
 
A

AlbaClause

Lawrence said:
Executable files can be kept anywhere, you don't need a special directory
for them.

Yes, I know, but if you want to just enter the filename at the shell prompt,
the file has to be somewhere that it can be found. Otherwise you get the
dreaded "command not found" error. Unless I'm doing something wrong?


--
 
S

Stargaming

AlbaClause said:
Lawrence D'Oliveiro wrote:




Yes, I know, but if you want to just enter the filename at the shell prompt,
the file has to be somewhere that it can be found. Otherwise you get the
dreaded "command not found" error. Unless I'm doing something wrong?
In the most cases, PATH is preconfigured to include "." (. is the
current directory as .. is the parent one). You can use
../yourpythonscript in this case.
Another possibility is using `python script.py` to let the python
interpreter do the work directly.
The most "advanced" way would be expanding PATH with
/home/youraccount/python/learning (use PATH=$PATH:/path/here..).

Choose the one you're most comfortable with. :)

Sincerely,
Stargaming
--
 
J

Jorge Godoy

Stargaming said:
In the most cases, PATH is preconfigured to include "." (. is the current
directory as .. is the parent one). You can use ./yourpythonscript in this
case.

I most cases on Unix boxes it isn't configured to include ".". This is so for
safety reasons (somebody might replace some command with a tampered binary or
a script and capture information that they shouldn't have access to...).

The solution of creating a directory and adding it to PATH is the best one,
IMHO. Having a "~/bin" is also common for Linux and some distributions of it
already ship with it in /etc/skel and in the PATH, so just put a link there or
copy your scripts there.
The most "advanced" way would be expanding PATH with
/home/youraccount/python/learning (use PATH=$PATH:/path/here..).

Yes. This is the best.
Choose the one you're most comfortable with. :)

;-) And think about security as well.
 
J

Jorgen Grahn

I most cases on Unix boxes it isn't configured to include ".".

Indeed -- but "Stargaming" might have missed a negation somewhere, because
he went on to say

[rearranged from the above]
which is precisely what you /don't/ need to type if you have placed . in
your $PATH.
The solution of creating a directory and adding it to PATH is the best one,
IMHO. Having a "~/bin" is also common for Linux and some distributions of it
already ship with it in /etc/skel and in the PATH, so just put a link there or
copy your scripts there.


Yes. This is the best.

I wouldn't want random scripts under development ending up in my $PATH, not
even my own.

When you're just playing with/developing scripts, it's better to execute
them by path (./foo.py etc). When you think they work and you have a
long-term use for them, you install them globally, or copy, move or link
them into your ~/bin/.

/Jorgen
 

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
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top