GtkWarning: could not open display

妖精的绣舞 提交于 2019-12-30 07:29:10

问题


I am trying to run a spider on a vps (using scrapyjs which uses python-gtk2). On running the spider I am getting the error

/root/myporj/venv/local/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display

How do I run this in a headless setup?


回答1:


First of all, you didn't specify if you have a desktop environment (or X) installed on your server?

Regardless of that, you can achieve headless setup for your spider by using xvfb:

Xvfb or X virtual framebuffer is a display server implementing the X11 display server protocol. In contrast to other display servers Xvfb performs all graphical operations in memory without showing any screen output. From the point of view of the client, it acts exactly like any other X display server, serving requests and sending events and errors as appropriate. However, no output is shown. This virtual server does not require the computer it is running on to even have a screen or any input device.

First, install xvfb on your server. Assuming you are using apt-get:

sudo apt-get install xvfb

Now, run the xvfb service at a custom display number, like:

sudo Xvfb :5

After that, you can run any application that requires X inside your virtual frame buffer by exporting the display number and running your application:

export DISPLAY=:5
run_my_application

The DISPLAY is set only for the current terminal session, so keep that in mind when implementing automation for this step.




回答2:


Probably you run the application over ssh? Then, you need to run X server on local PC. If not, you should set DISPLAY environment variable correctly. Recently, sudo command on Ubuntu doesn't some transfer environment variable. If you run the application over sudo, make sure $DISPLAY is set or not.

Additional

It's a bug of pygtk. You app should be depend on gtk widget.

https://bugs.launchpad.net/ubuntu/+source/software-center/+bug/800574



来源:https://stackoverflow.com/questions/27646435/gtkwarning-could-not-open-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!