The following script has the purpose to upload all .xyz files into QGIS that are within the folder xyz_data. That's the script:

from qgis.core import QgsVectorLayer, QgsProject
import glob, os

dir = "C:/Users/user/Desktop/xyz_data"


for file in glob.glob("*.xyz"):
    uri = "file://" + dir + file + "?delimiter=%s&xField=%s&yField=%s" % (" ", "field_1", "field_2")
    name = file.replace('.xyz', '')
    lyr = QgsVectorLayer(uri, name, "delimitedtext")

When I run the command in the python console the names of the files appear in the QGIS layerlist but there is no data and I get an attention sign next to the layer. There is no attribute table I could open nor can I zoom to the layer

enter image description here

Hovering over the attention sign gives me the following error message:

No available Layer! Layer data source was not found.

Apparently it has something to do with the uri. However, I don't see any errors in the code. The directory is correct, I went to the folder and copy & pasted the url.

Perhaps there is something wrong with writing + file +?

Perhaps I don't get the whole filename as a string?

The delimiter is correct as well. The xField and yField names are correct as well I think. The file itself already starts with the x-coordinate and doesn't have a line called xField, however when I upload each file manually, QGIS represents the columns as "field_1" and so on.

Does anyone see the error?


1 Answer 1


You need to append a forward slash in your dir so that it looks like:

dir = "C:/Users/user/Desktop/xyz_data/"

And as you figured out, you need three forward slashes when defining the file url:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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