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
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
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)