2

This question already has an answer here:

I am creating a plugin for QGIS where I, amongst other things, have to create a shapefile layer.

My problem is using the QgsVectorLayer. I tried following the answer in Problem creating point shapefiles programmatically using python in QGIS 2.2

Which works great if I call it in the Python console in QGIS, but if I try to do it from my plugin, I get the error: "NameError: global name 'QgsVectorLayer' is not defined".

I am using QGIS 2.16.3


I already have 'from PyQt4.QtCore import *' shouldn't that be enough?


For some reason I thought qgis.core and PyQt4.QtCore were the same thing. It was the missing imports.

marked as duplicate by Germán Carrillo, PolyGeo Nov 6 '16 at 22:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You need to import the classes you need to use in the header of the Python file, for instance: from qgis.core import QgsVectorLayer If you need more classes from qgis.core, just append them, for instance: from qgis.core import QgsVectorLayer, QgsPoint – Germán Carrillo Nov 6 '16 at 19:34

Browse other questions tagged or ask your own question.