Страница 1 из 1
AttributeError: 'module' object has no attribute 'argv'
Добавлено: 09 июн 2012, 11:07
Cathrin
Подскажите,пожалуйста,как можно исправить эту ошибку?
Код: Выделить всё
Traceback (most recent call last):
File "C:\Users\Cathrin/.qgis/python/plugins\HelloWorld\HelloWorld.py", line 53, in hello_world
MyProgramme = QApplication(sys.argv)
AttributeError: 'module' object has no attribute 'argv'
Версия Python:
2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
Версия:
1.8.0-Lisboa Lisboa, a1255fc
вот мой код
Код: Выделить всё
import sys,os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
MyProgramme = QApplication(sys.argv)
MainWidget = QVBox(None)
MainWidget.setCaption("Hello!")
HelloLabel = QLabel("Hello World!", MainWidget)
CloseButton = QPushButton("Quit", MainWidget)
MyProgramme.setMainWidget(MainWidget)
MyProgramme.connect(CloseButton, SIGNAL("clicked()"), MainWidget, SLOT("close()"))
MainWidget.show()
MyProgramme.exec_loop()
Re: AttributeError: 'module' object has no attribute 'argv'
Добавлено: 09 июн 2012, 11:44
Александр Мурый
В трейсбэке сказано про строку 53, в примере строк явно меньше..
У меня указанный кусок кода тоже не работает, но пишет совсем другое:
Код: Выделить всё
Traceback (most recent call last):
File "./test.py", line 9, in <module>
MainWidget = QVBox(None)
NameError: name 'QVBox' is not defined
Re: AttributeError: 'module' object has no attribute 'argv'
Добавлено: 09 июн 2012, 11:50
Cathrin
ну просто я не совсем весь код кинула
остальное работало до того как я вставила кусок того кода
вот абсолютно весь
Код: Выделить всё
# -*- coding: utf-8 -*-
# Import the PyQt and QGIS libraries
import sys,os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
class HelloWorld:
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
self.canvas = iface.mapCanvas()
def initGui(self):
# Create action that will start plugin
self.action = QAction(QIcon(":/plugins/"), "&HelloWorld", self.iface.mainWindow())
# connect the action to the run method
QObject.connect(self.action, SIGNAL("activated()"), self.hello_world)
# Add toolbar button and menu item
self.iface.addPluginToMenu("HelloWorld", self.action)
def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu("HelloWorld",self.action)
# run
def hello_world(self):
QMessageBox.information(self.iface.mainWindow(), QCoreApplication.translate('HelloWorld', "HelloWorld"), QCoreApplication.translate('HelloWorld', "HelloWorld"))
f=open('temp/op.txt', 'w')
layer = self.iface.activeLayer()
feats = layer.selectedFeatures()
for feat in feats:
attrs = feat.attributeMap()
for (k,attr) in attrs.iteritems():
if k in [0,1,2]:
if k ==1:
f.write("%d:Ploshad - %s\r\n" % (k, attr.toString()))
if k ==2:
f.write("%d:Nomer vylela - %s\r\n" % (k, attr.toString()))
MyProgramme = QApplication(sys.argv)
MainWidget = QVBox(None)
MainWidget.setCaption("Hello!")
HelloLabel = QLabel("Hello World!", MainWidget)
CloseButton = QPushButton("Quit", MainWidget)
MyProgramme.setMainWidget(MainWidget)
MyProgramme.connect(CloseButton, SIGNAL("clicked()"), MainWidget, SLOT("close()"))
MainWidget.show()
MyProgramme.exec_loop()
f.close()
if __name__ == "__main__":
pass
Re: AttributeError: 'module' object has no attribute 'argv'
Добавлено: 09 июн 2012, 11:52
Cathrin
http://rfpro.ru/forum/15/241
я пытаюсь выполнить вот такую вещь,которая описывается там
Re: AttributeError: 'module' object has no attribute 'argv'
Добавлено: 09 июн 2012, 14:08
Ariki
Я, конечно, не совсем в теме, но, может быть, не стоит создавать QApplication из плагина QGIS?
Re: AttributeError: 'module' object has no attribute 'argv'
Добавлено: 09 июн 2012, 14:45
Voltron
Cathrin, вы определитесь, что вы хотите сделать: модуль или самостоятельное приложение. У вас в коде дикая мешанина.
Да, изучать PyQt лучше не по форуму, а по нормальной книге (например,
такой) +
документации. Без азов вы постоянно будет теряться в элементарных вещах