回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我是软件开发新手,我正在使用cx_freeze来生成一个你好.py使用PyQt5模块的python文件。以下错误重复出现。我使用的是python3.6和PyQt5。在</p>
<p><img src="https://i.stack.imgur.com/JtFv9.jpg" alt="image"/></p>
<p>AttributeError:模块'lxml.etrr型“”没有属性“fromstring”</p>
<p><img src="https://i.stack.imgur.com/RIV4L.jpg" alt="image"/></p>
<p>下面是我的你好.py文件</p>
<pre><code>import sys
import time
import wikipedia
import docx
import requests
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
doc = docx.Document()
class App(QMainWindow):
def __init__(self):
super().__init__()
self.title = 'Articulate - tecbeast.com'
self.left = 50
self.top = 100
self.width = 400
self.height = 300
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
lbl1 = QLabel(self)
lbl1.setText("Please enter the topics you want to print articles on")
lbl1.setGeometry(20,20,400,40)
lbl2 = QLabel(self)
lbl2.setText('Topics should be separeted by comma ","')
lbl2.setGeometry(20,40,400,40)
lbl3 = QLabel(self)
lbl3.setText('Make sure that your pc is connected to the internet')
lbl3.setGeometry(20,60,400,40)
# Create textbox
self.textbox = QLineEdit(self)
self.textbox.move(20, 100)
self.textbox.resize(280,40)
# Create a button in the window
self.button = QPushButton('Make Article', self)
self.button.move(20,160)
# connect button to function on_click
self.button.clicked.connect(self.on_click)
self.show()
def shw_wt(self):
#for the showing of label Please wait
lbl4 = QLabel(self)
lbl4.setText('Please wait')
lbl4.setGeometry(20,135,400,40)
lbl4.show()
@pyqtSlot()
def on_click(self):
self.shw_wt()
cur_topic = self.textbox.text()
topics = cur_topic.split(",")
for ech_topic in topics:
try:
para = wikipedia.summary(ech_topic, sentences = 100)
except wikipedia.exceptions.DisambiguationError as e:
para = wikipedia.summary(e.options[0], sentences = 100)
except requests.exceptions.ConnectionError as e:
pop_up = QMessageBox.question(self, 'Warning!', 'You are not connected to the internet', QMessageBox.Ok)
if pop_up == QMessageBox.Ok:
self.initUI()
#problem in above line
else:
pass
doc.add_heading (ech_topic,0)
doc.add_paragraph(para)
n = str(time.time())
doc.save(n+".docx")
pop_up = QMessageBox.question(self, 'All Done', 'Your article is made. Check your current directory', QMessageBox.Ok)
if pop_up == QMessageBox.Ok:
pass
else:
pass
#lbl4.hide()
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
</code></pre>