3

I've just tried to install QGIS 3.0 package in my Anaconda (Win7x64, Python 3.6 x64). I wanted to use QGIS widgets in my PyQt application. Alas, QGIS works incorrectly: at first, when I just tried to import qgis modules in Python, it said that it cannot find them. And when I manually set the PYTHONPATH, QGISPATH and PATH variables, it simply does not show my map (only the blank white screen).

Under Ubuntu 18.04 the script works correctly (there I just made apt-get install python3-qgis).

Can you tell me, how can I make it work under Windows too?

Here's my test script:

#!/usr/bin/env python3

import os

from PyQt5.QtWidgets import QWidget, QFrame, QHBoxLayout, QGridLayout

from qgis._core import QgsApplication, QgsRasterLayer
from qgis._gui import QgsMapCanvas


class TestWidget(QWidget):
    def __init__(self, parent=None):
        super(TestWidget, self).__init__(parent)
        self.main_layout = QHBoxLayout(self)
        self.canvas = QgsMapCanvas()
        self.main_layout.addWidget(self.canvas)

        base_layer_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "world.mbtiles")
        self.base_layer = QgsRasterLayer(base_layer_path, 'world')
        self.canvas.setLayers([self.base_layer])
        self.canvas.zoomToFullExtent()


if __name__ == '__main__':
    qgs = QgsApplication([], False)
    qgs.setPrefixPath(os.environ.get('QGISPATH', '/usr'), True)
    qgs.initQgis()

    w = TestWidget()
    w.show()

    qgs.exec_()
    qgs.exitQgis()

And here's my test map data (world.mbtiles): https://www.sendspace.com/filegroup/8OqffqxS3aWuRdwr4iolRQ

And here are my environment variables (set under Windows):

PYTHONPATH=C:/Anaconda3/Library/python
QGISPATH=C:/Anaconda3
PATH=C:/Anaconda3/share/qgis/python/qgis;C:/Anaconda3/Library/bin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.