Reputation: 1128
I have a python script that when I run in terminal:
py filename.py
That works fine. But with this style:
./filename.py
I get Permission denied error. Any idea why? Thanks in advance.
Upvotes: 2
Views: 69
Reputation: 660
When you do ./filename.py
it executes the script.
When you do py filename.py
the py
program reads in your filename.py
and runs.
Upvotes: 2
Reputation: 7630
Your file needs to be marked as executable. You can see how its current permissions with ls(1)
and change its permissions with chmod(1)
:
ls -l filename.py
chmod a+x filename.py
You will also need to make sure that the first line of your script has the hashbang correctly:
#!/usr/bin/py
# the rest of your script...
Upvotes: 3
Reputation: 9216
You have three types of permissions in posix compiliant systems: read, write and execute. You simply don't have rights to execute the script. In order to add permissions you have to call something like:
chmod +x filename.py
You have to remember that ./filename.py
won't execute your Python script even if you will add execution rights (if you don't have #!/usr/bin/py
at the beginning). Python scripts need to be executed in an interpreter - not as a standalone application.
Upvotes: 1
Reputation: 2550
My guess is that python itself has -x (executable) rights, but filename.py does not
Upvotes: 3