I would like to add a vector layer to QGIS using the python console (and eventually in a separate python IDE). I have run the following code from the pyqgis cookbook:
layer = QgsVectorLayer(r'//Users//rwegener//repos//correlations//co_energy_weather_shpfiles//co_energy_weather.shp',
'degree_days', "memory")
if not layer.isValid():
print('layer failed to load')
The layer loads without a problem, however the layer is not valid.
The only other pages I have found on this suggest the user to mess around with slashes so I have also tried the following ways to input the layer:
layer = QgsVectorLayer(r'/Users//rwegener//repos//correlations//co_energy_weather_shpfiles//co_energy_weather.shp',
'degree_days', "memory")
layer = QgsVectorLayer(r'/Users/rwegener/repos/correlations/co_energy_weather_shpfiles/co_energy_weather.shp',
'degree_days', "memory")
layer = QgsVectorLayer(r'\\Users\\rwegener\\repos\\correlations\\co_energy_weather_shpfiles\\co_energy_weather.shp',
'degree_days', "memory")
When I load the file into QGIS with the "add vector layer" button there are no problems.
I have tried also with the cookbook method:
layer = iface.addVectorLayer(r'//Users//rwegener//repos//correlations//co_energy_weather_shpfiles//co_energy_weather.shp',
'degree_days', "memory")
only to get the error:
AttributeError: 'NoneType' object has no attribute 'addVectorLayer'
C://
beforeUsers//...