使用from pydocx import PyDocX将Word转成PDF报错
来源:3-10 Word转PDF
随心__
2023-10-10 19:52:35
import pdfkit from pydocx import PyDocX config = pdfkit.configuration(wkhtmltopdf=r"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe") # Word转PDF,需要先转成HTML然后才能转换为PDF html = PyDocX.to_html("简历1.docx") pdfkit.from_string(html, "test3.pdf", configuration=config) ========================================报错内容 File "I:\学习1\PDF操作\pdf操作.py", line 47, in <module> html = PyDocX.to_html("简历1.docx") ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python311\Lib\site-packages\pydocx\pydocx.py", line 13, in to_html return PyDocXHTMLExporter(path_or_stream).export() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python311\Lib\site-packages\pydocx\export\html.py", line 208, in export return ''.join( ^^^^^^^^ File "D:\Python311\Lib\site-packages\pydocx\export\html.py", line 208, in <genexpr> return ''.join( ^ File "D:\Python311\Lib\site-packages\pydocx\export\base.py", line 117, in export self._first_pass_export() File "D:\Python311\Lib\site-packages\pydocx\export\base.py", line 129, in _first_pass_export for result in self.export_node(document): File "D:\Python311\Lib\site-packages\pydocx\export\base.py", line 218, in export_node for result in results: File "D:\Python311\Lib\site-packages\pydocx\export\html.py", line 127, in apply for result in results: File "D:\Python311\Lib\site-packages\pydocx\export\base.py", line 218, in export_node for result in results: File "D:\Python311\Lib\site-packages\pydocx\export\html.py", line 127, in apply for result in results: File "D:\Python311\Lib\site-packages\pydocx\export\base.py", line 252, in yield_nested for result in func(item): File "D:\Python311\Lib\site-packages\pydocx\export\base.py", line 218, in export_node for result in results: File "D:\Python311\Lib\site-packages\pydocx\export\html.py", line 278, in export_paragraph results = is_not_empty_and_not_only_whitespace(results) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python311\Lib\site-packages\pydocx\export\html.py", line 78, in is_not_empty_and_not_only_whitespace for item in gen: File "D:\Python311\Lib\site-packages\pydocx\export\html.py", line 114, in apply results = is_not_empty_and_not_only_whitespace(results) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python311\Lib\site-packages\pydocx\export\html.py", line 78, in is_not_empty_and_not_only_whitespace for item in gen: File "D:\Python311\Lib\site-packages\pydocx\export\html.py", line 114, in apply results = is_not_empty_and_not_only_whitespace(results) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python311\Lib\site-packages\pydocx\export\html.py", line 78, in is_not_empty_and_not_only_whitespace for item in gen: File "D:\Python311\Lib\site-packages\pydocx\export\base.py", line 252, in yield_nested for result in func(item): File "D:\Python311\Lib\site-packages\pydocx\export\base.py", line 216, in export_node results = caller(node) ^^^^^^^^^^^^ File "D:\Python311\Lib\site-packages\pydocx\export\base.py", line 344, in export_run if run.effective_properties: ^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python311\Lib\site-packages\pydocx\util\memoize.py", line 24, in __call__ if not isinstance(args, collections.Hashable): ^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'collections' has no attribute 'Hashable' 进程已结束,退出代码1
1回答
同学,你好!尝试在如下路径"D:\Python311\Lib\site-packages\pydocx\util\memoize.py"的
memoize.py文件中,有导入collections的导入代码,改成collections.abc 。将24行的collections.Hashable改为collections.abc.Hashable再运行文件py文件看能否解决
祝学习愉快~
相似问题
回答 1