Standalone python script error on initQgs(): No vector layers can be loaded. #197
Trying to install qgis2, and have gotten as far as not being able to read a shapefile using PyQGIS from Homebrew python (i.e. a standalone python script). I can read the file just fine with QGIS.app.
I set the PYTHONPATH as advised by
The following script demonstrates the problem.
from qgis.core import * QgsApplication.setPrefixPath('/usr/local/Cellar/qgis2/2.18.2/QGIS.app/Contents/MacOS') qgs = QgsApplication(, False) qgs.initQgis() shp_file = 'path/to/shape/file.shp' vlayer = QgsVectorLayer(shp_file, 'vlayer') print vlayer.isValid() qgs.exitQgis()
The message generated at
Surely there is some additional environment variable to set? I tried using all the exports in the wrapper script
Hi @itcarroll, thanks for reporting! Apologies, as the docs in the wiki here are very outdated. For your Python standalone script's shell wrapper script (or environment), you can use:
After which, you can try this:
On an odd note, even after setting
which is of course waaaay wrong.
Let me know if you need any further explanation on the env variables used here.