Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to run certain Python files from Terminal. Permission denied?

What causes the below error?

-bash: ./proj.py: Permission denied

I have one file, called projsol.py, that runs perfectly out of terminal when I enter ./projsol.py --summary *.html in Terminal.

However, when I enter ./proj.py --summary *.html, I get the above error. I've literally copied and pasted the entire context of projsol.py into proj.py, tried running the command again, and it still gives me the above bash error. What's causing this?

Note: I am very new to programming, and have very unfamiliar with Terminal and Python, so please explain in layman's terms (it's much appreciated!).

like image 221
TheRealFakeNews Avatar asked Oct 01 '15 01:10

TheRealFakeNews


People also ask

Why am I getting a permission denied error in Python?

Permission denied simply means the system is not having permission to write the file to that folder. Give permissions to the folder using "sudo chmod 777 " from terminal and try to run it.

How do I fix bash permission denied?

Usually, you get the error bash permission denied when running some script/file that does not have execute permissions. It is one of the most common Magento errors. All you need to do to fix it is to change file permissions and add executive one.

Does Python script need execution permission to run?

Unlike a CGI script, Python scripts do not need to have execute permissions to run when you invoke them with the python command. Python is an interpreted language, which means that if you call the file with python [filename], Python itself handles the execution.


1 Answers

Run the chmod command against the file in the following manner:

sudo chmod +x proj.py

This assigns the executable bit to the file.

If that doesn't work run the following command, from the same directory as proj.py, and provide the output

ls -al

This will give you a dump of the directory as well as permissions and user/group permissions on the file. Something is not set correctly.

like image 59
Mike McMahon Avatar answered Nov 04 '22 20:11

Mike McMahon