Error : cannot connect to X server on Ubuntu

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Error : cannot connect to X server on Ubuntu

devquestions2@gmail.com
I am seeing the error "cannot connect to X server" in a stand alone python application at
"app = QgsApplication([], True)".

As suggested in the mailing archives I tried setting DISPLAY env variable to "", but that does not resolve the problem. Would be a great help if you can point me any references on the issue or have any suggestions on what i can try.

Os Ubuntu

code :

import os
import sys

#qgisprefix = '/usr'
qgisprefix='/usr/share/qgis/resources'


os.environ['DISPLAY']=""
from qgis.core import *

from qgis.gui import *

# configure QGIS paths
QgsApplication.setPrefixPath(qgisprefix, True)

# initalise QGIS
QgsApplication.initQgis()

app = QgsApplication([], True)

Thanks !
Reply | Threaded
Open this post in threaded view
|

Re: Error : cannot connect to X server on Ubuntu

Richard Duivenvoorde
On 09-12-14 14:16, [hidden email] wrote:

> I am seeing the error "cannot connect to X server" in a stand alone python
> application at
> "app = QgsApplication([], True)".
>
> As suggested in the mailing archives I tried setting DISPLAY env variable to
> "", but that does not resolve the problem. Would be a great help if you can
> point me any references on the issue or have any suggestions on what i can
> try.
>
> Os Ubuntu
>
> code :
>
> import os
> import sys
>
> #qgisprefix = '/usr'
> qgisprefix='/usr/share/qgis/resources'
>
>
> os.environ['DISPLAY']=""
> from qgis.core import *
>
> from qgis.gui import *_
>
> # configure QGIS paths
> QgsApplication.setPrefixPath(qgisprefix, True)
>
> # initalise QGIS
> QgsApplication.initQgis()
>
> app = QgsApplication([], True)

I'm on Debian here, and (given the right PYTHONPATH and LD_LIBRARY path
are correct), your code works for me.

Here:
http://comments.gmane.org/gmane.comp.gis.qgis.devel/34478
Martin tells something about the differences between the inits of qgis.
Setting the DISPLAY to "" as you do is actually setting it to NONE!

If you are in a X-session you should not need to set this. If you are
running it on a headless server, then it is possible you do not have X.

Are you sure ubuntu is actually running X? Wasn't ubuntu busy with
trying to make something else instead of X, mir or so?
Can you try it on another machine?

Regards,

Richard Duivenvoorde

_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Error : cannot connect to X server on Ubuntu

devquestions2@gmail.com
Hi Richard,

Thanks for the reply.

Can you please let me know what should be the values for

 PYTHONPATH and LD_LIBRARY .

Kindof new to this whole linux/unix world. Appreciate your help.

Thanks !
Reply | Threaded
Open this post in threaded view
|

Re: Error : cannot connect to X server on Ubuntu

devquestions2@gmail.com
>>on X-server,

I want to run it in a headless mode i.e no GUI. I want to be able to invoke in batch mode ( ie headless standalone)  a model developed via graphical modelling tool of qgis.

So, ideally i dont want to connect to x-server

this is needed for automation purpose.

Cant really use python consol from qgis.
Reply | Threaded
Open this post in threaded view
|

Re: Error : cannot connect to X server on Ubuntu

Ziegler Stefan
Hi

I think there are two approaches:

1) Install Xvfb and start it with the following command (and export DISPLAY):

Xvfb :99 -ac -noreset &
export DISPLAY=:99
 

2) Try to use QCoreApplication instead of QApplication:

app = QApplication(sys.argv)
QgsApplication.setPrefixPath("/home/stefan/Apps/qgis_master", True)
QgsApplication.initQgis()

I don't know what the drawbacks are when using QCoreApplication.

Regards
Stefan

> -----Urspr√ľngliche Nachricht-----
> Von: [hidden email] [mailto:qgis-developer-
> [hidden email]] Im Auftrag von [hidden email]
> Gesendet: Dienstag, 9. Dezember 2014 17:12
> An: [hidden email]
> Betreff: Re: [Qgis-developer] Error : cannot connect to X server on Ubuntu
>
> >>on X-server,
>
> I want to run it in a headless mode i.e no GUI. I want to be able to invoke in batch
> mode ( ie headless standalone)  a model developed via graphical modelling tool of qgis.
>
> So, ideally i dont want to connect to x-server
>
> this is needed for automation purpose.
>
> Cant really use python consol from qgis.
>
>
>
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/Error-cannot-
> connect-to-X-server-on-Ubuntu-tp5177029p5177061.html
> Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
> _______________________________________________
> Qgis-developer mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Error : cannot connect to X server on Ubuntu

Richard Duivenvoorde
In reply to this post by devquestions2@gmail.com
On 09-12-14 16:49, [hidden email] wrote:
> Hi Richard,
>
> Thanks for the reply.
>
> Can you please let me know what should be the values for
>
>  PYTHONPATH and LD_LIBRARY .

I compile QGIS master in debug mode and install it in
apps/qgis/master/debug

So then these are the paths I use

export PYTHONPATH=/home/richard/apps/qgis/master/debug/share/qgis/python/

export LD_LIBRARY_PATH=/home/richard/apps/qgis/master/debug/lib/

but if I understand correct you have an headless (without X-server)
config. That's a different beast.

Regards,

Richard
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Error : cannot connect to X server on Ubuntu

devquestions2@gmail.com
Yeah, I am trying to use headless application. I was able to overcome the earlier error, but now i am stuck with a new error message.

"QPixmap: Cannot create a QPixmap when no GUI is being used"
"QPixmap: Cannot create a QPixmap when no GUI is being used"
"QPixmap: Cannot create a QPixmap when no GUI is being used"

Now I am creating QApplication by passing flase for ui mode.
>>app = QgsApplication([], False)

Here is the revised code.

I thought someone should figured this out before.  It is so painful to use qgis in headless mode !!


import os
import sys

qgisprefix = '/usr'
#qgisprefix='/usr/share/qgis/resources'

# configure paths for QGIS
sys.path.insert(0, qgisprefix+'/share/qgis/python')
sys.path.insert(1, qgisprefix+'/share/qgis/python/plugins')

# disable QGIS debug messages
#os.environ['QGIS_DEBUG'] = '-1'
os.environ['DISPLAY']=""
# import QGIS modules
from qgis.core import *

#from qgis.gui import *

# configure QGIS paths
QgsApplication.setPrefixPath(qgisprefix, False)

# initalise QGIS
QgsApplication.initQgis()

app = QgsApplication([], False)

import processing
Reply | Threaded
Open this post in threaded view
|

Re: Error : cannot connect to X server on Ubuntu

Matthias Kuhn
The tests run on a headless server with xvfb.

So I assume that doing anything with

xvfb-run python yourapp.py

and no messing with display should work perfectly as well.

On 12/10/2014 08:50 PM, [hidden email] wrote:

> Yeah, I am trying to use headless application. I was able to overcome the
> earlier error, but now i am stuck with a new error message.
>
> "QPixmap: Cannot create a QPixmap when no GUI is being used"
> "QPixmap: Cannot create a QPixmap when no GUI is being used"
> "QPixmap: Cannot create a QPixmap when no GUI is being used"
>
> Now I am creating QApplication by passing flase for ui mode.
>>> app = QgsApplication([], False)
> Here is the revised code.
>
> I thought someone should figured this out before.  It is so painful to use
> qgis in headless mode !!
>
>
> import os
> import sys
>
> qgisprefix = '/usr'
> #qgisprefix='/usr/share/qgis/resources'
>
> # configure paths for QGIS
> sys.path.insert(0, qgisprefix+'/share/qgis/python')
> sys.path.insert(1, qgisprefix+'/share/qgis/python/plugins')
>
> # disable QGIS debug messages
> #os.environ['QGIS_DEBUG'] = '-1'
> os.environ['DISPLAY']=""
> # import QGIS modules
> from qgis.core import *
>
> #from qgis.gui import *
>
> # configure QGIS paths
> QgsApplication.setPrefixPath(qgisprefix, False)
>
> # initalise QGIS
> QgsApplication.initQgis()
>
> app = QgsApplication([], False)
>
> import processing
>
>
>
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/Error-cannot-connect-to-X-server-on-Ubuntu-tp5177029p5177312.html
> Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
> _______________________________________________
> Qgis-developer mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/qgis-developer

_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Error : cannot connect to X server on Ubuntu

devquestions2@gmail.com
thanks Matthias,

Actually this is what i am trying to do.

i need to calculate wetness index, so i have developed a model in qgis graphical modeler that invokes grss-saga algorithsm to calculate slope, wetness index etc.

all i want to do is to run that algorithm in a headless mode.

So, using processing model is the only way here or there are any other approaches ?

using xvfb-run  is an option, but it will complicate something else i.e i want then invoke the scripts via hadoop-mapreduce for parallel execution.

Reply | Threaded
Open this post in threaded view
|

Re: Error : cannot connect to X server on Ubuntu

Matthias Kuhn
I have never run a processing model standalone, so I cannot help there.
I don't know how closely tied this is to GUI related things. It may or
may not work without X. But if you have to create a QgsApplication which
is a QApplication I am pretty sure that you need to have some kind of X
running. So it would be a matter of getting processing to run without
QgsApplication.
How does hadoop-mapreduce work? Is it not possible to spawn one separate
xvfb-run process per map?


On 12/10/2014 08:58 PM, [hidden email] wrote:

> thanks Matthias,
>
> Actually this is what i am trying to do.
>
> i need to calculate wetness index, so i have developed a model in qgis
> graphical modeler that invokes grss-saga algorithsm to calculate slope,
> wetness index etc.
>
> all i want to do is to run that algorithm in a headless mode.
>
> So, using processing model is the only way here or there are any other
> approaches ?
>
> using xvfb-run  is an option, but it will complicate something else i.e i
> want then invoke the scripts via hadoop-mapreduce for parallel execution.
>
>
>
>
>
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/Error-cannot-connect-to-X-server-on-Ubuntu-tp5177029p5177316.html
> Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
> _______________________________________________
> Qgis-developer mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/qgis-developer

_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Documentation for QGIS server

Daniel Scholten
Dear QGIS developers,

I want to use QGIS-Server to
* create a WMS and a WFS,
* perform some GIS analysis on-the-fly within my interactive online map
to dynamically create new layers and
* enable users of my online map to manipulate some stored geodata.

I found some documentation [1,2,3,4,5], but did not achive to install
QGIS-server successfully locally on my Windows 7 machine. I also did not
found any API documentation. Can somebody give me a hint where to find
some more documentation? I am also interested in book recommondations.

Best wishes
Daniel

[1] http://hub.qgis.org/wiki/quantum-gis/QGIS_Server_Tutorial
[2]
http://qgis-documentation.readthedocs.org/en/latest/server/server.html
[3] http://live.osgeo.org/de/overview/qgis_mapserver_overview.html
[4]
http://anitagraser.com/2012/04/06/qgis-server-on-windows7-step-by-step/
[5]
http://linfiniti.com/2010/08/qgis-mapserver-a-wms-server-for-the-masses/
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Documentation for QGIS server

giohappy

Hi,
as far as I know there'n no more yhen what you already found. The "API" are the WMS/WFS http requests (+ vendor params). It doesn't have an API like UMN Mapserver.

What's going wrong with your setup?

giovanni


_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Documentation for QGIS server

Andreas Neumann-4
In reply to this post by Daniel Scholten
Hi Daniel,

Am 2014-12-11 08:51, schrieb Daniel Scholten:
> Dear QGIS developers,
>
> I want to use QGIS-Server to
> * create a WMS and a WFS,

This should be possible.

> * perform some GIS analysis on-the-fly within my interactive online
> map to dynamically create new layers and

This does not work out of the box. Will require some serverside
scripting. QGIS server is not yet a WPS server.

> * enable users of my online map to manipulate some stored geodata.

This depends on your client. QGIS server support WFS edits, but the QGIS
Web Client does not support editing. I heard that Lizmap supports it. Or
maybe you have another client.

Andreas
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Documentation for QGIS server

Alessandro Pasotti-2
2014-12-11 10:47 GMT+01:00 Andreas Neumann <[hidden email]>:

> Hi Daniel,
>
> Am 2014-12-11 08:51, schrieb Daniel Scholten:
>>
>> Dear QGIS developers,
>>
>> I want to use QGIS-Server to
>> * create a WMS and a WFS,
>
>
> This should be possible.
>
>> * perform some GIS analysis on-the-fly within my interactive online
>> map to dynamically create new layers and
>
>
> This does not work out of the box. Will require some serverside scripting.
> QGIS server is not yet a WPS server.
>
>> * enable users of my online map to manipulate some stored geodata.
>
>

Hi,

For server-side scripting, I would suggest you to check out the new
API for QGIS server Python plugins (I think it's only available in
master).

At the moment the documentation is still rare (I'm slowly working to
improve it).

By now you can start from here:

http://www.itopen.it/qgis/serverplugins/api/
https://github.com/elpaso/qgis-helloserver
http://www.itopen.it/2014/11/27/plugin-python-per-qgis-server/


--
Alessandro Pasotti
w3:   www.itopen.it
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Documentation for QGIS server

Daniel Scholten
Thanks Giovanni, Andreas and Alessandro for your help!

I got the QGIS-Server working now and have an idea about how I can do
what I want.

Best wishes
Daniel


On 2014-12-11 13:24, Alessandro Pasotti wrote:

> 2014-12-11 10:47 GMT+01:00 Andreas Neumann <[hidden email]>:
>> Hi Daniel,
>>
>> Am 2014-12-11 08:51, schrieb Daniel Scholten:
>>>
>>> Dear QGIS developers,
>>>
>>> I want to use QGIS-Server to
>>> * create a WMS and a WFS,
>>
>>
>> This should be possible.
>>
>>> * perform some GIS analysis on-the-fly within my interactive online
>>> map to dynamically create new layers and
>>
>>
>> This does not work out of the box. Will require some serverside
>> scripting.
>> QGIS server is not yet a WPS server.
>>
>>> * enable users of my online map to manipulate some stored geodata.
>>
>>
>
> Hi,
>
> For server-side scripting, I would suggest you to check out the new
> API for QGIS server Python plugins (I think it's only available in
> master).
>
> At the moment the documentation is still rare (I'm slowly working to
> improve it).
>
> By now you can start from here:
>
> http://www.itopen.it/qgis/serverplugins/api/
> https://github.com/elpaso/qgis-helloserver
> http://www.itopen.it/2014/11/27/plugin-python-per-qgis-server/
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-developer