gpt4 book ai didi

python - Gtk警告 : could not open display

转载 作者:太空宇宙 更新时间:2023-11-04 01:11:03 25 4
gpt4 key购买 nike

我正在尝试在 vps 上运行蜘蛛(使用使用 python-gtk2 的 scrapyjs)。在运行蜘蛛时我收到错误

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

如何在 headless 设置中运行它?

最佳答案

首先,您没有说明您的服务器上是否安装了桌面环境(或 X)?

无论如何,您可以使用 xvfb 为您的蜘蛛实现 headless 设置:

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.

首先,在您的服务器上安装xvfb。假设您正在使用 apt-get:

sudo apt-get install xvfb

现在,以自定义显示编号运行 xvfb 服务,例如:

sudo Xvfb :5

之后,您可以通过导出显示编号并运行您的应用程序,在您的虚拟帧缓冲区内运行任何需要 X 的应用程序:

export DISPLAY=:5
run_my_application

DISPLAY 仅为当前终端 session 设置,因此在为此步骤实现自动化时请记住这一点。

关于python - Gtk警告 : could not open display,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27646435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com