“无法连接到显示器"在EC2服务器上 [英] "Could not connect to display" on EC2 Server

查看:171
本文介绍了“无法连接到显示器"在EC2服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些熊猫数据框表导出为图像.我研究了许多解决方案,并发现了最好的选择.我遵循了此网站上的指示,并且在本地一切正常.

I'm trying to export some pandas dataframe tables as images. I looked at many solutions, and found what seemed like the best bet. I followed the directions on this site, and everything worked fine locally.

但是,当试图使此python脚本在EC2服务器上运行时,出现以下错误:

However, when trying to get this python script to run on an EC2 server, I get the following error:

OSError: wkhtmltoimage exited with non-zero code 1. error:
qt.qpa.screen: QXcbConnection: Could not connect to display 
Could not connect to any X display.


You need to install xvfb(sudo apt-get install xvfb, yum install xorg-x11-server-Xvfb, etc), then add option: {"xvfb": ""}.

我尝试按照指示安装到xfvb,但这是行不通的(我想是因为从另一个库中调用了wkhtmltopdf).我启动了一个新服务器,从头开始重新安装一切,以消除该潜在问题.还是一无所有.

I tried install to xfvb as directed, but that doesn't work (I imagine because wkhtmltopdf is being called from another library). I spun up a new server to re-install everything from scratch to eliminate that potential issue. Still nothing.

我用Google搜索了这个问题,并尝试了一些随机建议,但没有骰子.

I Googled the issue and tried some random suggestions, but no dice.

我的目标是从pandas数据框生成SVG文件(转换为html).是否可以形成没有监视器的云服务器?有没有更好的方法可以为熊猫生成PDF报告的表格图像?

My goal is to produce an SVG file from a pandas dataframe (converted to html). Is this possible to do form a cloud server with no monitor? Is there a better way to produce table images for PDF reports from pandas?

一些代码:

import pandas
data = pandas.read_csv(open("biostats.csv", "r"))

css = """
<style type=\"text/css\">
table {
color: #333;
font-family: Helvetica, Arial, sans-serif;
width: 640px;
border-collapse:
collapse; 
border-spacing: 0;
}"""

text_file = open("filename.html", "a")
# write the CSS
text_file.write(css)
# write the HTML-ized Pandas DataFrame
text_file.write(data.to_html())

imgkitoptions = {"format": "svg"}
imgkit.from_file("filename.html", outputfile, options=imgkitoptions)
text_file.close()

推荐答案

尝试在远程主机上执行echo $DISPLAY.如果结果为空,则表示您未连接任何显示屏,因此不会显示输出.

try doing echo $DISPLAY on your remote host. If it turns out empty, it means you are not connected to any display screen and hence, the output will not be displayed.

如果是这种情况,请尝试执行export DISPLAY=localhost:10.0,然后重新运行原始命令

If that's the case try doing export DISPLAY=localhost:10.0 and then re-run your original command

注意:连接到远程服务器时,请使用ssh -X

Note: when connecting to the remote server use ssh -X

这篇关于“无法连接到显示器"在EC2服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆