Wednesday, 13 May 2015

pyqgis - QGIS 2.99 "qgis._core import error: DLL load failed"



I am trying to run a standalone application. However, it does not run the program because of mentioned error in title. Here is my code:


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()
exitcode = app.exec_()
QgsApplication.exitQgis()
sys.exit(exitcode)

When I run it, I get this error:


Traceback (most recent call last):
File "C:/Users/DELL/Desktop/MyMap/myMap.py", line 1, in
from qgis.core import *
File "C:\OSGeo4W64\apps\qgis-dev\python\qgis\__init__.py", line 72, in

from qgis.core import QgsFeature, QgsGeometry
File "C:\OSGeo4W64\apps\qgis-dev\python\qgis\core\__init__.py", line 34, in
from qgis._core import *

ImportError: DLL load failed: The specified module could not be found.


Python version is: 3.6 PyQt version is: PyQt5.9 Windows 10 - 64bit


I also add many path:


%SystemRoot%\system32
%SystemRoot%
%SystemRoot%\System32\Wbem

%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
C:\OSGeo4W64
C:\OSGeo4W64\apps
C:\OSGeo4W64\apps\gdal-dev
C:\OSGeo4W64\apps\gdal-dev\bin
C:\OSGeo4W64\apps\gdal-dev\pymod3\Lib\site-packages
C:\OSGeo4W64\apps\grass\grass-7.2.2\bin
C:\OSGeo4W64\apps\Python36
C:\OSGeo4W64\apps\Python36\Scripts
C:\OSGeo4W64\apps\Python36\DLLs

C:\OSGeo4W64\apps\Python36\lib\site-packages
C:\OSGeo4W64\apps\qgis-dev
C:\OSGeo4W64\apps\qgis-dev\bin
C:\OSGeo4W64\apps\qgis-dev\lib
C:\OSGeo4W64\apps\qgis-dev\python
C:\OSGeo4W64\apps\qgis-dev\python\qgis
C:\OSGeo4W64\apps\Qt5
C:\OSGeo4W64\apps\Qt5\lib
C:\OSGeo4W64\bin
C:\OSGeo4W64\apps\qgis-dev\python

C:\OSGeo4W64\apps\Python36\lib
C:\OSGeo4W64\include
C:\Users\Mustafa Uçar\AppData\Roaming\QGIS\QGIS3\profiles\default
C:\Users\Mustafa Uçar\AppData\Roaming\QGIS\QGIS3\profiles\default\QGIS

How can I fix this error?



Answer



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!


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...