[GIS] Python Error using MMQGIS, global name ‘math’ not defined

mmqgisqgis-plugins

I am using QGIS 2.16 and trying to compute distances between two points using the MMQGIS plug-in (Hub -distance). This worked like a charm, but recently I have been getting a Python Error whenever I change the measurement unit from "layer unit" to any of the other. The error message is:

"   Traceback (most recent call last):
              File "/Users/henry/.qgis2/python/plugins/mmqgis/mmqgis_dialogs.py",   line 1727, in run
                nameattributename, units, addlines, savename, evenly_distributed, 1)
              File "/Users/henry/.qgis2/python/plugins/mmqgis/mmqgis_library.py", line 4169, in mmqgis_hub_distance
                hubdist = mmqgis_distance(source[0], hub[0])
              File "/Users/henry/.qgis2/python/plugins/mmqgis/mmqgis_library.py", line 544, in mmqgis_distance
                start_lon = start.x() * math.pi / 180
            NameError: global name 'math' is not defined"

Does anybody know how to resolve this issue?

Best Answer

If you want to fix it by yourself: Go to Plugin-Directory mmqgis and open the file mmqgis_library.py there you'll find the lines:

# Used instead of "import math" so math functions can be used without "math." prefix
from math import *

So, everywhere in the file, you have to delete math. in any occurence, eg. math.cos becomes just cos. Anyway, the author should be informed!!

Related Question