I am using QGIS 2.18.5 and the Profiletool 4.0.2. plugin I tried to save my profile to an .png file and this resulted with an error:

Traceback (most recent call last):
File "C:/Users/b/.qgis2/python/plugins\profiletool\ui\ptdockwidget.py", line 567, in saveAs self.outPNG()
File "C:/Users/b/.qgis2/python/plugins\profiletool\ui\ptdockwidget.py", line 587, in outPNG PlottingTool().outPNG(self.iface, self, self.mdl, self.cboLibrary.currentText ())
File "C:/Users/b/.qgis2/python/plugins\profiletool\tools\plottingtool.py", line 525, in outPNG wdg.profiletoolcore.loaddirectory = os.path.dirname(fileName)
NameError: global name 'os' is not defined

The same with exporting to .svg or .dxf

How can I fix it?

Profiletool 4.0.2. plugin (profile.py) itself already imports os:

import sys
import os
import time
import marshal
from optparse import OptionParser

However, I guess it is somehow correlated with it's predecessor - plottingtool.py which actually prints the error. The latter does not import os:

from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import *
import qgis

    from qgis.PyQt.QtWidgets import *

from . import resources
from .tools.profiletool_core import ProfileToolCore
  • Fails with the command "os.path.dirname"...have you tried importing os first? (with the command: import os) – T. Wayne Whitley Apr 5 '17 at 19:21
  • I added more info above. Should I just type import os in the plottingtool.py? I tried and did not help. How should I import it? I am totally blue as it comes to scripting. – lukabana Apr 5 '17 at 20:09
  • Although I do not know how and why, the problem has been solved. The plugin works well after I reinstalled numpy and matplotlib due to another, unrelated issue. – lukabana Apr 18 '17 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.