Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

QXcbConnection: Could not connect to display #14376

Closed
arrmo opened this issue Jun 26, 2016 · 24 comments
Closed

QXcbConnection: Could not connect to display #14376

arrmo opened this issue Jun 26, 2016 · 24 comments

Comments

@arrmo
Copy link

arrmo commented Jun 26, 2016

  1. Which version of PhantomJS are you using? Tip: run phantomjs --version.
    2.1.1
  2. What steps will reproduce the problem?
    1. Take a working javascript file (e.g. rasterize.js)
    2. Call the file from a script file (e.g. executable file, #!/bin/sh at the start)
    3. Now execute the script file as a cron job
  3. Which operating system are you using?
    Ubuntu 16.04 LTS
  4. Did you use binary PhantomJS or did you compile it from source?
    Binary - installed it as part of Ubuntu (using apt).
  5. Please provide any additional information below.
    This is very similar to QXcbConnection: Could not connect to display #14240, but I am using the stock version of PhantomJS (with Ubuntu). Below is the output from running the cron job (which calls the script file, to generate a pdf file once a day) ...

QXcbConnection: Could not connect to display
PhantomJS has crashed. Please read the bug reporting guide at
http://phantomjs.org/bug-reporting.html and file a bug report.
Aborted (core dumped)

Thanks!

@vitallium
Copy link
Collaborator

Please check your environment variable QT_QPA_PLATFORM. It must be empty.

@arrmo
Copy link
Author

arrmo commented Jun 29, 2016

Yep, it is - in both cases. Does this need to be manually forced for some reason?

Thanks!

@zackw
Copy link
Contributor

zackw commented Jun 30, 2016

I would send a patch to reset all the troublesome environment variables before initializing Qt ... if I could find a list of them anywhere.

But it sounds like this isn't actually the problem?

@arrmo
Copy link
Author

arrmo commented Jun 30, 2016

It doesn't sound like it, but I could definitely be wrong.

@arrmo
Copy link
Author

arrmo commented Jul 11, 2016

Trying different things, no luck. Is there a setting of QT_QPA_PLATFORM that you believe may help?

Thanks!

@ricohumme
Copy link

Hi,

Having same issue here.
Working with 1.9 on my dev machine, works fine.
But on the live server I can't even download 1.9.x so I'm stuck now.

Where can I find this settings of QT? How to get there. So I can check that on my side.

Thanks!

@jglogan
Copy link

jglogan commented Jul 29, 2016

The offscreen platform is a usable workaround for me with the stock Ubuntu package. This works for me:

QT_QPA_PLATFORM=offscreen phantomjs rasterize.js 2i8zaNg04d9B41Zir2kT3J/output.html 2i8zaNg04d9B41Zir2kT3J.png

@oiwn
Copy link

oiwn commented Aug 4, 2016

can confirm export QT_QPA_PLATFORM=offscreen before selenium scripts work's well.

@ricohumme
Copy link

We finally got things working by downloading the binary at https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 and extracting the phantomjs to /usr/bin

@oiwn
Copy link

oiwn commented Aug 4, 2016

I had hard times with ubuntu 16.04 they basically distribute half finished system with lots of broken packages.

@ricohumme
Copy link

I'm running on 16.04 too, but the problem with the repo's is that they deliver with x11, which fails. So with the binary I don't have that issue and it works perfectly now.

@arrmo
Copy link
Author

arrmo commented Aug 13, 2016

Works here now also - thanks!!!

@ariya
Copy link
Owner

ariya commented Aug 14, 2016

Debian/Ubuntu has a modified version of PhantomJS that can work headlessly, hence the problem with QXcb. See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=817277 for details.

Unfortunately, this is not something that we (=PhantomJS team) can fix.

@ariya ariya closed this as completed Aug 14, 2016
bjodah added a commit to bjodah/pycvodes that referenced this issue Aug 31, 2016
bjodah added a commit to bjodah/pycvodes that referenced this issue Aug 31, 2016
@3zzy
Copy link

3zzy commented Sep 11, 2016

@ricohumme Can you provide the steps (commands) to install it? I tried:

export PHANTOM_JS_VERSION=2.1.1
wget "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2"
tar xvfj "./phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2"
ln -sf "./phantomjs-$PHANTOM_JS_VERSION-linux-x86_64/bin/phantomjs" "/usr/bin"

but still couldn't get it working

@ricohumme
Copy link

@3zzy the steps I used are as follows:
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
bzip2 -d phantomjs-2.1.1-linux-x86_64.tar.bz2
tar -xvf phantomjs-2.1.1-linux-x86_64.tar
cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs

Does this help your case?

@HideoKun
Copy link

HideoKun commented Dec 2, 2016

Thanks for help, solution above works well :)

@elhamdaoui
Copy link

elhamdaoui commented Feb 27, 2017

I have the same error but in Odoo

@seachanged
Copy link

xvfb-run worked best for me, from Ariya's link posted 8/2016.
xvfb is "providing an unobtrusive way to run applications that don’t really need an X server but insist on having one anyway."

@michaelkl
Copy link

@jglogan Thank you for solution with QT_QPA_PLATFORM=offscreen. It let me run phantomjs itself, but it was failing for me with EOFError: end of file reached message on certain pages.
After some experiments with different platforms I found out that it works like a charm with QT_QPA_PLATFORM=minimal.
Hope this will help someone.

@Dingo64
Copy link

Dingo64 commented May 19, 2017

It seems that QT_QPA_PLATFORM=offscreen is not perfect. It works on Debian 8 jessie amd64 with PhantomJS 2.1.1 when you want to show version info:

# QT_QPA_PLATFORM=offscreen phantomjs --version
2.1.1

but it fails when you try to, for example, render a website:

[FATAL] QFontDatabase: Cannot find font directory /usr/lib/x86_64-linux-gnu/fonts - is Qt installed correctly?

So I just extracted phantomjs binary from https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 and this one works great.

To be honest most of the binaries on my server are from archives like this. The ones installed with apt-get often doesn't work (like phantomjs), are outdated or contain a lot of unnecessary files.

@ip1981
Copy link

ip1981 commented Dec 8, 2017

Debian/Ubuntu has a modified version of PhantomJS that can work headlessly, hence the problem with QXcb. See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=817277 for details.

This is quite the opposite:

Unfortunately it can not be fixed in Debian. To achieve headless-ness
upstream statically link with customised QT + Webkit. We don't want to ship
forks of those projects. It would be great to eventually convince upstream to
use standard libraries.

There is also a suggestion to use xvfb-run, which is right.

@eunick
Copy link

eunick commented Jan 8, 2018

try to uninstall phantomjs and just download the binary then create the softlink. that works for me..

apt-get remove phantomjs
ln -s /opt/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs

@fuzzygroup
Copy link

I can absolutely confirm what ricohumme said:

We finally got things working by downloading the binary at https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 and extracting the phantomjs to /usr/bin

What we found was that without this specific version of phantomjs on Ubuntu 16, no text would appear in the rendered pdf files. We ran it as:

QT_QPA_PLATFORM=phantom QT_QPA_FONTDIR=/usr/share/fonts phantomjs ../vendor/assets/javascripts/rasterize.js file.html file.pdf letter

And that successfully rendered a pdf.

@jorgesinval
Copy link

Every time I try to plot anything with RStudio Cloud using the webshot package I obtain an error. An example:

#install webshot
library(webshot)
webshot::install_phantomjs()
# Make the graph
my_graph=wordcloud2(demoFreq, size=1.5)
# save it in html
library("htmlwidgets")
saveWidget(my_graph,"tmp.html",selfcontained = F)
# and in png
webshot("tmp.html","fig_1.png", delay =5, vwidth = 480, vheight=480)

The error says:

QXcbConnection: Could not connect to display :0
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
Error in webshot("tmp.html", "fig_1.png", delay = 5, vwidth = 480, vheight = 480) : 
  webshot.js returned failure value: -6

Any thoughts?

pavelhoral pushed a commit to orchitech/wrenam that referenced this issue Aug 1, 2021
`QT_QPA_PLATFORM=offscreen" is used to resolve the error "QXcbConnection: Could not connect to display" from PhantomJS, per ariya/phantomjs#14376 (comment).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests