[GIS] How to import CSV layer to QGIS using PyQGIS in Windows

csvpyqgisqgis

I'm using QGIS 2.18.14 Las Palmas on Windows 8.1
I tried to import CSV layer to QGIS using this script:

uri = 'file://D:/26mei.csv?d?delimiter=%s&xField=%s&yField=%s' % (",", "Lon", "Lat")
layer_csv = QgsVectorLayer(uri, 'paramHilal', 'delimitedtext')
QgsMapLayerRegistry.instance().addMapLayer(layer_csv)

The last line is to add the CSV layer to layer panel in QGIS, but it didn't appear. It could be because the layer is not valid.
I knew because I have tried layer_csv.isValid() and it return False. But I don't know where my mistake is.
Does anyone knows why my script is not work?

PS: I have tried this on QGIS 2.8 Wien on Ubuntu 16.04 and it worked just fine.

Best Answer

Just a tip according to this: Use PyQGIS to import CSV and draw points using different color

use /// instead // after file.