ターミナルで実行すると、次のPythonスクリプトがあります。
py filename.py
それはうまくいきます。しかし、このスタイルでは:
./filename.py
Permission denied エラーが発生します。理由はありますか?前もって感謝します。
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...
私の推測では、python 自体には -x (実行可能) 権限がありますが、filename.py にはありません。
これを行う./filename.py
と、スクリプトが実行されます。
あなたがするときpy filename.py
、py
プログラムはあなたを読み込んでfilename.py
実行します。
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.