I am trying to do some basic computations using the PGRouting plugin for QGIS, but I am getting this error all time:

An error has occured while executing Python code:

Traceback (most recent call last):
  File "C:/Users/Gonzalo/.qgis2/python/plugins\pgRoutingLayer\pgRoutingLayer.py", line 407, in run
    if db and db.con:
UnboundLocalError: local variable 'db' referenced before assignment

Python version:
2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]

QGIS version:
2.2.0-Valmiera Valmiera, c3a2817

Python path: ['C:/Users/Gonzalo/.qgis2/python/plugins\\processing', 'C:/PROGRA~1/QGISVA~1/apps/qgis/./python', u'C:/Users/Gonzalo/.qgis2/python', u'C:/Users/Gonzalo/.qgis2/python/plugins', 'C:/PROGRA~1/QGISVA~1/apps/qgis/./python/plugins', 'C:\\PROGRA~1\\QGISVA~1\\bin\\python27.zip', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\DLLs', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\plat-win', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\lib-tk', 'C:\\PROGRA~1\\QGISVA~1\\bin', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\site-packages', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\site-packages\\PIL', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\site-packages\\win32', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\site-packages\\Shapely-1.2.18-py2.7-win-amd64.egg', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\site-packages\\six-1.3.0-py2.7.egg', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\site-packages\\xlrd-0.9.2-py2.7.egg', 'C:\\PROGRA~1\\QGISVA~1\\apps\\Python27\\lib\\site-packages\\xlwt-0.7.5-py2.7.egg', '.', 'C:\\PROGRA~1\\QGISVA~1\\apps\\qgis\\python\\plugins\\fTools\\tools']

I made a local installation of postgres 9.3.4, later I added postgis using the stack builder, and finally I followed the instructions posted here: PGRouting 2.0 for windows. I also installed python-psycopg2 for my version of python.

The SQL query runs well in pgAdminIII, but I can not make that QGIS plugin work.

  • 1
    I have seen this kind of error at the different post. Could you check the user name and password are saved at creating connection time ? gis.stackexchange.com/questions/87111/…
    – sanak
    Apr 8, 2014 at 5:00
  • Dear sanak, your answer has solved my problem. Thank you so much.
    – gtapko
    Apr 8, 2014 at 5:24

1 Answer 1


In order to make the plugin work, I needed to save both my username and password on the database connection.

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.