I was getting the same error but I found this command to help with that:
xhost si:localuser:root
Just type this in the terminal of your project and you won't get that error anymore, you will however have to install Pillow and some other packages so follow the error to resolve your issues.
Hope this helps.