I'm running weasyprint project on ubuntu 18.04 and I try to create a a pdf.
The problem started when I try to set a footer image. I'm running on python 3.6.7
This is my code invoking 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'
Maybe is related to #746.
Hello!
read_text is a method of Path and its subclasses as PosixPath. As it's been added in Python 3.5, I think that you're not running Python 3.6.7 but Python 3.4.x or older. Maybe the python3 executable you're launching is not the one installed on your system, but another version bundled with Node or its modules? You can add print(sys.version) in your script to be sure.
Maybe is related to #746.
I don't think it is.
Hi!
I certify the python version like you suggest:

I recreate my dockerfile to test and now I using version 3.7 of python.
I recreate my dockerfile to test and now I using version 3.7 of python.
So… You get the same error with Python 3.7?
Yes! Same error :face_with_head_bandage:
And if you add this code at the beginning of your script:
from pathlib import Path
print(Path().read_text)
What do you get?
Same error:
3.7.2 (default, Feb 6 2019, 12:04:03)
[GCC 6.3.0 20170516]
Traceback (most recent call last):
File "/node_modules/my-project/python/run.py", line 5, in <module>
print(Path().read_text)
AttributeError: 'PosixPath' object has no attribute 'read_text'
In my pyhton project I got a requiriments.txt and I put pathlib as requirement. Somehow this pathlib overrides the current lib installed althogether python 3.5 or higher.
When I remove this dependencie the problem is solved.
Thank u for your time, I really appreciate the support. :1st_place_medal:
Thank u for your time, I really appreciate the support.
:heart:
Hi, I faced the exact same problem while deploying a venv, which has a read_text function in importlib_metadata. Even after removing pathlib from my requirements.txt, the error is not going away. Any leads would be highly appreciated.
File "/opt/python/run/venv/local/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 405, in read_text
AttributeError: 'PosixPath' object has no attribute 'read_text'
Hi, I faced the exact same problem while deploying a venv, which has a read_text function in importlib_metadata. Even after removing pathlib from my requirements.txt, the error is not going away. Any leads would be highly appreciated.
You have to uninstall pathlib from your environment, using pip uninstall pathlib.
Most helpful comment
You have to uninstall pathlib from your environment, using
pip uninstall pathlib.