Kwan Xian

How to run python script include GPIO config ?

Recommended Posts


when I build a pthon3 script with gui and GPIO contorl.I can run it when I use terminal with sudo command.

But when I used "settings->session and startup" to config this script,It can't run when my device reboot (Orange Pi PC).

I try to config command like:

"echo 'password'|sudo -S python3 /home/kwan/OPi_PC/u_main.py"

still the same.

And then I tried to edit "/etc/rc.local" file and add:

"echo 'password'|sudo -S python3 /home/kwan/OPi_PC/u_main.py &"

still the same.


The problem is when I run the other script without GPIO config and sudo command.

It can run when device reboot.


So,It's there anybody can tell me why & how to make it run with sudo.

I really have no idea about it.




@reboot sudo python3 /home/kwan/OPI_PCPLUS/Linux_gate.py > /home/kwan/log.log

Error: no display name and no $DISPLAY environment variable



Share this post

Link to post
Share on other sites

Hi Kwan Xian,  I don't know which software you use, you might want to checkout this one:


Within armbian you find following User-Supported options for GPIO and more:
UserSpaceIO (libgpiod),
pyGPIO accesses 'pins' directly through /dev/mem

 User Space IO is Python 3 and Java 8 bindings for user space GPIO, SPI, I2C, PWM and Serial interfaces


 pyGPIO - A 'more general' python GPIO library based on pyA20


Share this post

Link to post
Share on other sites
On 1/14/2019 at 5:00 AM, martinayotte said:

It can be workarounded also using setuid on python itself :



Yes,You'r right.

cp /usr/bin/python3 to /usr/bin/my-python and chmod 4775 /usr/bin/my-python.

config "my-python {script-path}" for startup command.

Now,my py script can run when device reboot.

Thank You!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now