wkhtmltopdf(pdfkit)无法连接到任何X显示器 [英] wkhtmltopdf (pdfkit) Could not connect to any X display

查看:45
本文介绍了wkhtmltopdf(pdfkit)无法连接到任何X显示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将wkhtmltopdf与Django,nginx,uwsgi一起使用它非常适合在使用manage.py runserver运行的开发环境中运行但是当与nginx ans uwsgi一起使用时,出现此错误:

I am trying to use wkhtmltopdf with Django ,nginx,uwsgi it works perfectly on development env running using manage.py runserver but when serving with nginx ans uwsgi i get this error:

wkhtmltopdf exited with non-zero code 1. error:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-isp'
qt.qpa.screen: QXcbConnection: Could not connect to display 
Could not connect to any X display.

Exception Location:     /home/isp/Env/isp/lib/python3.6/site-package/pdfkit/pdfkit.py in to_pdf, line 159

命令:

wkhtmltopdf http://www.google.com output.pdf

在终端上完美运行我用这个向导来部署Django应用

works perfectly on terminal and i used this guid to deploy the Django app https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04#setting-up-the-uwsgi-application-server

我认为它与virtualenv有关,我尝试使用此包装器 https://github.com/JazzCore/python-pdfkit/wiki/Using-wkhtmltopdf-without-X-server

i think it is related to virtualenv , i tried using this wrapper https://github.com/JazzCore/python-pdfkit/wiki/Using-wkhtmltopdf-without-X-server

但仍然存在相同的错误

mycode:

import pdfkit
    pdfkit.from_file("./invoices/invoice"+str(booking_id)+"-"+str(invoice_id)+".html", "invoices/invoice_initial"+str(booking_id)+"-"+str(invoice_id)+".pdf")

推荐答案

解决方案

代替使用

apt-get install wkhtmltopdf

我从发行页面下载了最新版本,一切正常.

I downloaded the latest version from the releases page and everything works now.

这篇关于wkhtmltopdf(pdfkit)无法连接到任何X显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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