我最近安装了 python-docx 包,但在使用默认模板时遇到了一些问题。我只是设置一个文档并具有以下代码(在名为 maintitle.py 的文件中):
from docx import Document
from docx.shared import Inches
document = Document()
但是,我收到以下错误:
Traceback (most recent call last):
File "/Users/myname/Desktop/Python/maintitle.py", line 4, in <module>
document = Document()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/docx/api.py", line 25, in Document
document_part = Package.open(docx).main_document_part
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/docx/opc/package.py", line 128, in open
pkg_reader = PackageReader.from_file(pkg_file)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/docx/opc/pkgreader.py", line 32, in from_file
phys_reader = PhysPkgReader(pkg_file)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/docx/opc/phys_pkg.py", line 31, in __new__
"Package not found at '%s'" % pkg_file
docx.opc.exceptions.PackageNotFoundError: Package not found at '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/docx/templates/default-docx-template'
查看目录“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/docx/templates”,只有四个文件:
default-footer.xml default-settings.xml
default-header.xml default-styles.xml
我使用 pip3 install python-docx 安装了 python-docx。我应该做点别的吗?