BBB: running simple PySide code, but getting error "cannot connect to X Server"

I am trying to run simple python(PySide) code on BBB(debian) , but getting error “cannot connect to x server” after compilation. My code is

import sys
from PySide import QtGui
app = QtGui.QtApplication(sys.argv) —> this line giving error “cannot connect to x server”

I have checked whether there is x server running on BBB with “ps aux | grep X” command, and it returned list of processes running X server.
Xorg -config command also gave message “there is x server with display 0” or a message very close to this.

Typing commands below also did not help me.

$export DISPLAY=:0.0


No protocol specified cannot connect to X server :0.0

Could you please help me resolve this issue?

Solved this problem. To be able to access X server I just needed to run the code as a normal user not as a root user. So I ssh’ed to beaglebone black as a “debian” user and ran the code. It was simple pyside code without any integration with GPIO’s or I2C’es. In case you want to access/modify these pins you must deal with privileges of “debian” user.