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 /home/pi/Desktop/control/gpio.py
into the command line, I get the message
bash: /home/pi/Desktop/control/gpio.py Permission denied
I have tried running sudo -s
before running that command also but that doesnt work. My python script is using the Rpi.GPIO
library.
If someone could please explain why I am getting this error it would be appreciated!
You will get this error because you do not have the execute
permission on your file. There are two ways to solve it:
python gpio.py
python will load the file by reading it, so you don't need to have execute permission.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With