i'm new to raspi. I try to run a python script from terminal (with typing not autostart when boot) Firstly, i directed the directory to my desired folder with cd /desireddirectory Then i try to run my python script with python name.py I got an error : Cannot connect to X Server BTW, i am using a monitor to start my pi which mean its not remotely like using a laptop with ssh connection via putty or what

  • 3
    Hello and welcome. Looks like your script want's to use the x server for some GUI. Check that X is installed and running (e.g. startx).
    – Ghanima
    Nov 12, 2014 at 8:36

1 Answer 1


You can only run text based programs from the serial console, if want to start an X11 program that will display on the video out you need to make sure your DISPLAY environment variable is set to the Xserver running on the pi. If it's networked and there is another Xserver that allows remote connections (another, properly configured pi, a properly configured macbook etc.) you can point the DISPLAY variable to that instead.
You probably just need to run

export DISPLAY="localhost:0"  

before running your program (assuming your login shell is bash, and that the pi has an Xserver running on one of screens and is running as display 0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.