Beaglebone Black: PySide program giving "cannot connect to X server"

Hi everyone, I did research about this problem in google group but unfortunately was not able to find any answer.
I am trying to run simple pyside code on BBB(debian) and getting error “cannot connect to X server”. My sample code is

import sys
from PySide import QtGui
app = QtGui.QApplication(sys.argv) —> after this line i am getting that error message.
sys.exit(app.exec_())

I did search and tried these steps to give a permission to the root user to use X server

export DISPLAY=127.0.0.1:0.0
xhost local:root —> and getting this error "unable to open display “127.0.0.1:0.0"”

I checked whether X server is available and got the message “Server is already active for display 0”.
ps aux | grep X command also returned list of processes using X server.

Could you please help me resolve this issue?