Hello, <br><br>I have this error when I run my plugin my code is below. What may be the problem? <br><br>Thanks,<br>Lutfi<br><br>P.S. : I tried something for this problem the line begin # mark are the things that I tried.<br>
<br># Import the PyQt and QGIS libraries<br>from PyQt4 import QtCore, QtGui<br><br>from PyQt4.QtCore import * <br>from PyQt4.QtGui import *<br>from qgis.core import *<br>from os import *<br>from qgis.gui import *<br>import sys<br>
import pdb<br># Initialize Qt resources from file resources.py<br>import resources<br># Import the code for the dialog<br>from ReadDataDialog import ReadDataDialog<br><br>class ReadData: <br><br>  def __init__(self, iface):<br>
    # Save reference to the QGIS interface<br>    self.iface = iface<br><br>  def initGui(self):  <br>    # Create action that will start plugin configuration<br>    self.action = QAction(QIcon(&quot;:/plugins/readdata/icon.png&quot;), \<br>
        &quot;Read shp for calculations&quot;, self.iface.mainWindow())<br>    # connect the action to the run method<br>    QObject.connect(self.action, SIGNAL(&quot;triggered()&quot;), self.run) <br><br>    # Add toolbar button and menu item<br>
    self.iface.addToolBarIcon(self.action)<br>    self.iface.addPluginToMenu(&quot;&amp;Read shp for calculations&quot;, self.action)<br><br>  def unload(self):<br>    # Remove the plugin menu item and icon<br>    self.iface.removePluginMenu(&quot;&amp;Read shp for calculations&quot;,self.action)<br>
    self.iface.removeToolBarIcon(self.action)<br><br>  # run method that performs all the real work<br>  def run(self): <br>       <br>#    fileName = QFileDialog.getOpenFileName(None,QString.fromLocal8Bit(&quot;Select a file:&quot;),&quot;&quot;, &quot;*.shp *.gml&quot;)<br>
    <br>#    if fileName.isNull():<br><br>#      QMessageBox.information(None, &quot;Cancel&quot;, &quot;File selection canceled&quot;)<br>      <br>     <br><br><br>#    else:<br><br>#      print fileName<br>      <br><br>
    vlayer = QgsVectorLayer(&quot;C://Users//lutfi//Documents//tezzzz//data//roads.shp&quot;, &quot;hebe&quot;, &quot;ogr&quot;)<br>    print vlayer.source()<br>    print vlayer.featureCount()<br>    QgsMapLayerRegistry.instance().addMapLayer(vlayer)<br>
    QMessageBox.information(self.iface.mainWindow(), &quot;info&quot;, &quot;file: &quot;+str(vlayer.source())+&quot; is added.&quot;)<br>     <br><br>    <br>    <br>        <br>    if not vlayer.isValid():<br>      print &quot;Couldn&#39;t open the layer&quot;<br>
      pdb.set_trace()<br><br>    else:<br>      <br>#    QMessageBox.information(None, &quot;Cancel&quot;, &quot;File selection canceled&quot;)<br>   <br>      provider = vlayer.dataProvider()<br>      feat = QgsFeature()<br>
      allAttrs = provider.attributeIndexes()<br>      provider.select(allAttrs)<br>    <br>      while provider.nextFeature(feat):<br>        geom = feat.geometry()<br>        import sys<br>        import os <br>#        win32api.SetFileAttributes(&#39;C://Users//lutfi//Documents//tezzzz//log.txt&#39;, win32con.FILE_ATTRIBUTE_NORMAL)<br>
        sys.stdout = open(&#39;C://Users//lutfi//Documents//tezzzz//log.txt&#39;, 777 )<br>        print geom<br>#        QMessageBox.information(None, &quot;Cancel&quot;, &quot;File selection canceled&quot;)<br>        print &quot;Feature ID %d: &quot; % <a href="http://feat.id">feat.id</a>()<br>
        if geom.type() == QGis.Point:<br>          x = geom.asPoint()<br>          print &quot;Point: &quot; + str(x)<br><br>        elif geom.type() == QGis.Line:<br>          x = geom.asPolyline()<br>          print &quot;Line: %d points&quot; % len(x)<br>
<br>        elif geom.type() == QGis.Polygon:<br>          x = geom.asPolygon()<br>          numPts = 0<br>          for ring in x:<br>            numPts += len(ring)<br>            print &quot;Polygon: %d rings with %d points&quot; % (len(x), numPts)<br>
        else:<br>          print &quot;Unknown&quot;<br>          <br>        attrs = feat.attributeMap()<br><br>        for (k,attr) in attrs.iteritems():<br>          print &quot;%d: %s&quot; % (k, attr.toString())<br>          <br>
<br><br><br><br><br>        <br>        <br>      <br><br>