[英]AttributeError: 'PosixPath' object has no attribute 'read_text' while building heroku app
[英]Weasyprint get undefined property at invoking write_pdf: "AttributeError: 'PosixPath' object has no attribute 'read_text'"
我在 ubuntu 18.04 上運行 weasyprint 項目,並嘗試創建 aa pdf。
當我嘗試設置頁腳圖像時,問題就開始了。 我在 python 3.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.txt,並將
pathlib
作為要求。 以某種方式,該pathlib會覆蓋安裝了python 3.5或更高版本的當前lib。 當我消除這種依賴性時,問題就解決了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.