2

ターミナルで実行すると、次のPythonスクリプトがあります。

py filename.py

それはうまくいきます。しかし、このスタイルでは:

./filename.py

Permission denied エラーが発生します。理由はありますか?前もって感謝します。

4

4 に答える 4

3

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...
于 2013-02-01T20:09:15.753 に答える
3

私の推測では、python 自体には -x (実行可能) 権限がありますが、filename.py にはありません。

于 2013-02-01T20:07:31.420 に答える
2

これを行う./filename.pyと、スクリプトが実行されます。

あなたがするときpy filename.pypyプログラムはあなたを読み込んでfilename.py実行します。

于 2013-02-01T20:07:37.547 に答える
1

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.

于 2013-02-01T20:08:35.243 に答える