今天用cursor生成的代码,其中用到了docx,我试了一下,发现报错了。
报错代码:
import docx
import os
# create a new document
doc = docx.Document()
# add a heading to the document
doc.add_heading('helloworld')
# add a paragraph to the document
doc.add_paragraph('今天真开心')
# save the document to '工作总结' directory
if not os.path.exists('工作总结'):
os.makedirs('工作总结')
doc.save('工作总结/helloworld.docx')
报错信息如下:
ModuleNotFoundError: No module named 'exceptions'
大意是这个模块不存在!
明明已经导入了docx这个模块了,还是提示不存在,并且要使用的Save方法以及add_paragraph也不存在,这就有点郁闷了。
于是换了个模块,pip uninstall docx 然后再安装一下python-docx这个模块就可以正常使用了。!
标签: python基础