Weasyprint在调用WRITE_pdf:&Quot;AttributeError:'PosiPath'对象没有属性'Read_Text'时获取未定义的属性

Weasyprint get undefined property at invoking write_pdf: quot;AttributeError: #39;PosixPath#39; object has no attribute #39;read_text#39;quot;(Weasyprint在调用WRITE_pdf:Quot;AttributeError:#39;PosiPath#39;对象没有属性#39;Read_Text#39;时获取未定义的属性) - IT屋-程序员软件开发技术分
本文介绍了Weasyprint在调用WRITE_pdf:&Quot;AttributeError:'PosiPath'对象没有属性'Read_Text'时获取未定义的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ubuntu 18.04上运行weasyprint项目,并尝试创建一个pdf。

当我尝试设置页脚图像时,问题开始了。我使用的是python3.6.7

这是我调用weasyprint的代码:

import sys
import os
from weasyprint import HTML, CSS

htmlFile = sys.argv[1]
pdfFile = sys.argv[2]

html = HTML(filename=htmlFile)

css = CSS(string='@page { @bottom-center { width: 125%; margin-top: 10px; content: " "; background-image: url(file://' + os.getcwd() + '/pdf/footer.png); background-repeat: no-repeat; background-position: right;  background-size: 100%; } }')

html.write_pdf(pdfFile, stylesheets=[css])

但随后我收到以下错误:

Error: Command failed: python3 /node_modules/my-project/python/run.py /node_modules/my-project/pdf/catalog_01e299a3-1fca-482b-a512-e1bea832559f.html /node_modules/my-project/pdf/catalog_01e299a3-1fca-482b-a512-e1bea832559f.pdf
Traceback (most recent call last):
File "/node_modules/my-project/python/run.py", line 3, in <module>
    from weasyprint import HTML, CSS
File "/node_modules/my-project/python/weasyprint/__init__.py", line 394, in <module>
    from .css import preprocess_stylesheet  # noqa
File "/node_modules/my-project/python/weasyprint/css/__init__.py", line 25, in <module>
    from . import computed_values
File "/node_modules/my-project/python/weasyprint/css/computed_values.py", line 17, in <module>
    from .. import text
File "/node_modules/my-project/python/weasyprint/text.py", line 14, in <module>
    import cairocffi as cairo
File "/node_modules/my-project/python/cairocffi/__init__.py", line 19, in <module>
    VERSION = __version__ = (Path(__file__).parent / 'VERSION').read_text().strip()
AttributeError: 'PosixPath' object has no attribute 'read_text'

推荐答案

我在这里得到一些帮助后解决了这个问题: https://github.com/Kozea/WeasyPrint/issues/807

问题恢复到下面:

在我的PYHTON项目中,我得到了一个Requiriments s.txt,并将pathlib作为需求。不知怎么的,这个路径库覆盖了当前安装的库,尽管它安装了python3.5或更高版本。 当我删除此依赖项时,问题就解决了。

这篇关于Weasyprint在调用WRITE_pdf:&Quot;AttributeError:&#39;PosiPath&#39;对象没有属性&#39;Read_Text&#39;时获取未定义的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)