3

I have looked every pages, links, forums etc. It is a standalone application.

I add all paths that I can find to the PATHS and PYTHONPATH is here:

C:\OSGeo4W64\apps\qgis-dev\python
C:\OSGeo4W64\apps\qgis-dev\python\plugins
C:\OSGeo4W64\apps\qgis-dev\python\qgis

However it doesn't work and gives the same error for 12 days...

from qgis.core import *
from qgis.gui import *
from qgis.utils import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

app = QgsApplication([], True)
path = "C:/OSGeo4W64/apps/qgis-dev"
app.setPrefixPath(path, True)
app.initQgis()

canvas = QgsMapCanvas()
title = "PyQGIS Standalone Application Example"
canvas.setWindowTitle(title)
canvas.setCanvasColor(Qt.white)

layer_info = 'LineString?crs=epsg:4326'
layer = QgsVectorLayer(layer_info, 'MyLine', "memory")
pr = layer.dataProvider()
linstr = QgsFeature()
wkt = "LINESTRING (1 1, 10 15, 40 35)"
geom = QgsGeometry.fromWkt(wkt)
linstr.setGeometry(geom)
pr.addFeatures([linstr])
layer.updateExtents()
QgsProject.instance().addMapLayer(layer)
canvas.setExtent(layer.extent())
canvas.setLayers([layer])
canvas.zoomToFullExtent()
canvas.show()
exitcode = app.exec_()
# QgsApplication.exitQgis()
sys.exit(exitcode)

Here is the error:

Traceback (most recent call last):
  File "C:/Users/Mustafa Uçar/Desktop/sil.py", line 1, in <module>
    from qgis import _core
  File "C:\OSGeo4W64\apps\qgis-dev\python\qgis\__init__.py", line 72, in <module>
    from qgis.core import QgsFeature, QgsGeometry
  File "C:\OSGeo4W64\apps\qgis-dev\python\qgis\core\__init__.py", line 34, in <module>
    from qgis._core import *
ImportError: DLL load failed: Specified module could not found.

System information:

QGIS 2.99 - Python 3.6 - Win10*64

0
3

I have been working for 3 weeks for this problem. However, I found it finally. I write python console in qgis:

import sys
print (sys.path)

It gives the path and I paste them into PYTHONPATH and PATH. That's it!

4
  • 1
    Out of interest, what was the path? :) – Joseph Oct 27 '17 at 11:55
  • It is not enough to write here :) But you can get them by using command that I mentioned. It seems silly but yesterday I had a nosebleed because of strees :/ – Mustafa Uçar Oct 27 '17 at 12:54
  • Ahh, I thought there might have been a missing path you missed but good to know the problem is fixed! And try not to get too stressed =) – Joseph Oct 27 '17 at 12:58
  • 1
    It's beyond my power not to be stressed :) THANK YOU! – Mustafa Uçar Oct 27 '17 at 13:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.