简体   繁体   English

Weasyprint 在调用 write_pdf 时获得未定义的属性:“AttributeError: 'PosixPath' 对象没有属性 'read_text'”

[英]Weasyprint get undefined property at invoking write_pdf: "AttributeError: 'PosixPath' object has no attribute 'read_text'"

I'm running weasyprint project on ubuntu 18.04 and I try to create aa pdf.我在 ubuntu 18.04 上运行 weasyprint 项目,并尝试创建 aa pdf。

The problem started when I try to set a footer image.当我尝试设置页脚图像时,问题就开始了。 I'm running on python 3.6.7我在 python 3.6.7 上运行

This is my code invoking weasyprint:这是我调用 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])

But then I got following error:但后来我收到以下错误:

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'

I solve the problem after some help here: https://github.com/Kozea/WeasyPrint/issues/807 我在这里获得一些帮助后解决了这个问题: https : //github.com/Kozea/WeasyPrint/issues/807

The problem resume below: 问题在下面恢复:

In my pyhton project I got a requiriments.txt and I put pathlib as requirement. 在我的pyhton项目中,我得到了requiriments.txt,并将pathlib作为要求。 Somehow this pathlib overrides the current lib installed althogether python 3.5 or higher. 以某种方式,该pathlib会覆盖安装了python 3.5或更高版本的当前lib。 When I remove this dependencie the problem is solved. 当我消除这种依赖性时,问题就解决了。

I had this same error while trying to install a package through pip install , but I did need pathlib in my project, so I couldn't simply remove the dependency.我在尝试通过pip install安装包时遇到了同样的错误,但我的项目中确实需要 pathlib,所以我不能简单地删除依赖项。

I found the solution here我在这里找到了解决方案

Basically, you have to run pip3 instead of pip基本上,你必须运行pip3而不是pip

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 'PosixPath' object 在构建 heroku 应用程序时没有属性 'read_text' - AttributeError: 'PosixPath' object has no attribute 'read_text' while building heroku app AttributeError:“列表”对象没有属性“ write_pdf” - AttributeError: 'list' object has no attribute 'write_pdf' graph.write_pdf(“iris.pdf”) AttributeError: &#39;list&#39; 对象没有属性 &#39;write_pdf&#39; - graph.write_pdf(“iris.pdf”) AttributeError: 'list' object has no attribute 'write_pdf' AttributeError: &#39;PosixPath&#39; 对象没有属性 &#39;path&#39; - AttributeError: 'PosixPath' object has no attribute 'path' 如何将 Jupyter 部署到 Medium? “AttributeError: 'PosixPath' object 没有属性 'read' - How do I deploy Jupyter to Medium? "AttributeError: 'PosixPath' object has no attribute 'read' 在服务器上运行 collectstatic :AttributeError: &#39;PosixPath&#39; 对象没有属性 &#39;startswith&#39; - Running collectstatic on server : AttributeError: 'PosixPath' object has no attribute 'startswith' 在 Google Colab 中使用 pathlib:AttributeError: 'PosixPath' object 没有属性 'ls' - Using pathlib in Google Colab: AttributeError: ‘PosixPath’ object has no attribute ‘ls’ AttributeError:&#39;property&#39;对象没有属性 - AttributeError: 'property' object has no attribute Python-AttributeError:“ NoneType”对象没有属性“ get_text” - Python - AttributeError: 'NoneType' object has no attribute 'get_text' AttributeError: &#39;NoneType&#39; 对象没有属性 &#39;get_text&#39; - AttributeError: 'NoneType' object has no attribute 'get_text'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM