Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied for Python script using Bash?

I am new to Ubuntu... I am trying to run my first simple python program "Hello World" ... After running following commands in terminal

1. chmod +x filename.py 
2. ./filename.py

terminal is showing following error "bash: ./filename.py: Permission denied" what can I do for solve about problem?

like image 437
Ammu Avatar asked Jun 16 '12 03:06

Ammu


People also ask

How do I fix bash permission denied?

Solution to fix the bash: ./program_name: permission denied error. chmod u+x program_name– In this line, the chmod command will change the access mode to execute, denoted by x. only the file's owner will have the permission to execute the file.

How do I fix permission denied Python?

To resolve this error, we can use the chmod command, which stands for change mode . The chmod() requires two arguments, the path of the file/folder you want to access and the file mode.

How do I run bash script Permission denied?

To fix the permission denied error in Linux, one needs to change the file permission of the script. Use the “chmod” (change mode) command for this purpose.

How do I get permission to run a bash script?

We can provide the executable permission by using the below command, chmod +x filename.sh. chmod (Change Mode) - Using chmod we can change the access permissions to file system objects. +x - It makes the file executable.


1 Answers

Do you have the appropriate incantation at the top of your python file? e.g.,

#!/usr/bin/python (or alternatively #!/usr/bin/env python)

Just to clarify, chmod +x only makes a file executable, it doesn't run it.

And I'm assuming your script looks like nothing more complex than this:

#!/usr/bin/env python
print 'hello world'
like image 77
Levon Avatar answered Oct 11 '22 08:10

Levon