Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Permission Denied

Reply
Thread Tools

Permission Denied

 
 
Tom Strickland
Guest
Posts: n/a
 
      08-20-2006
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
 
Reply With Quote
 
 
 
 
hiaips
Guest
Posts: n/a
 
      08-20-2006

Tom Strickland wrote:
> 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?

 
Reply With Quote
 
 
 
 
AlbaClause
Guest
Posts: n/a
 
      08-20-2006
hiaips wrote:

>
> Tom Strickland wrote:
>> 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?


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


--
--
There are several things that I will never be:
* I will never be attracted to females.
* I will never enjoy the company of others.
Exactly how these realities bode for my enemy, is not of my concern.

 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      08-20-2006
In message <cPRFg.1547$(E-Mail Removed)>, AlbaClause wrote:

> 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.
 
Reply With Quote
 
AlbaClause
Guest
Posts: n/a
 
      08-20-2006
Lawrence D'Oliveiro wrote:

> In message <cPRFg.1547$(E-Mail Removed)>, AlbaClause wrote:
>
>> 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.


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?


--
--
There are several things that I will never be:
* I will never be attracted to females.
* I will never enjoy the company of others.
Exactly how these realities bode for my enemy, is not of my concern.

 
Reply With Quote
 
Stargaming
Guest
Posts: n/a
 
      08-20-2006
AlbaClause schrieb:
> Lawrence D'Oliveiro wrote:
>
>
>>In message <cPRFg.1547$(E-Mail Removed)>, AlbaClause wrote:
>>
>>
>>>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.

>
>
> 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
--
 
Reply With Quote
 
Jorge Godoy
Guest
Posts: n/a
 
      08-20-2006
Stargaming <(E-Mail Removed)> writes:

> 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.

--
Jorge Godoy <(E-Mail Removed)>
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      08-20-2006
On Sun, 20 Aug 2006 10:35:31 -0300, Jorge Godoy <(E-Mail Removed)> wrote:
> Stargaming <(E-Mail Removed)> writes:
>
>> In the most cases, PATH is preconfigured to include "." (. is the current
>> directory as .. is the parent one).

>
> 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]
>> You can use ./yourpythonscript in this
>> case.


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.
>
>> The most "advanced" way would be expanding PATH with
>> /home/youraccount/python/learning (use PATH=$PATH:/path/here..).

>
> 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

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org> R'lyeh wgah'nagl fhtagn!
 
Reply With Quote
 
Magnus Lycka
Guest
Posts: n/a
 
      08-23-2006
Jorge Godoy wrote:
> And think about security as well.


I.e. put '.' in the end of your PATH, never in the beginning!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixed: The machine-default permission settings do not grant Local Activation permission for the COM Server application with CLSID {555F3418-D99E-4E51-800A-6E89CFD8B1D7} to the user NT AUTHORITY\LOCAL SERVICE SID (S-1-5-19). Skybuck Flying Windows 64bit 1 06-29-2009 06:17 PM
Workgroup Permission Denied (Usually) Bob Ryan Wireless Networking 2 09-28-2007 09:46 PM
bash: ./firefox-installer: /bin/sh: bad interpreter: Permission denied damon Firefox 7 08-29-2007 08:50 PM
Can't do setuid and file permission denied Chris Perl 1 10-28-2003 03:34 PM
bash: /root/remstats.pl: /usr/bin/perl: bad interpreter: Permission denied Goblin Perl 1 08-14-2003 11:11 AM



Advertisments