I would like to load all raster layers with type .xyz which are in a folder into my QGIS Project using PyQGIS and wrote the following function

    for lyr in glob.glob(os.path.join(inputDir, "* .xyz")):
        rasterlyr = QgsRasterLayer(lyr , "")

I'm getting the following error message:

QgsProject.addMapLayers(): argument 1 has unexpected type 'QgsRasterLayer'

But according to the Dokumentation "Cheat Sheet" this should actually work.

Does anyone see the mistake?


You used QgsProject.instance().addMapLayers(rasterlyr) with a s while you are giving a single raster layer. You need to use the singular version or to give a list of layers (even with a single layer in the list).

Either do




My preference is the first one.

Your Answer

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

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