Permission Denied when executing python file in linux

前端 未结 3 1095
刺人心
刺人心 2020-12-21 09:52

I am working with my Raspberry Pi 2 B+ and I am using Raspbian. I have a python script located at /home/pi/Desktop/control/gpio.py

When I type /hom

3条回答
  •  轮回少年
    2020-12-21 10:39

    You will get this error because you do not have the execute permission on your file. There are two ways to solve it:

    1. Not executing the file in the first place. By running python gpio.py python will load the file by reading it, so you don't need to have execute permission.
    2. Granting yourself execute permission. You do this by running chmod u+x yourfile.py.

      However, doing so will not work unless you add a shebang at the top of your python program. It will let your linux know which interpreter it should start. For instance:

      #!/usr/bin/env python
      

      This would try to run python using your current $PATH settings. If you know which python you want, put it here instead.

      #!/usr/bin/python3
      

      Remember the shebang must be the very first line of your program.

提交回复
热议问题