WeasyPrint usage with Python 3.x on Windows

2024/10/11 16:31:08

I can't seem to get WeasyPrint to work on Windows with Python 3.4 or 3.5. Has anyone been able to do this? There aren't forums at weasyprint.org and the IRC channel is dead.

I've been able to install using both Python 3.4.3 and 3.5.1. I've followed the guideline found here [1]. I've also made note that WeasyPrint's site claims it should work with Python 2.6+ or 3.1+.

When I install for Python 3.4.3 and open the Python shell and simply 'import weasyprint' I get this:

C:\Python34>python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import weasyprint
Traceback (most recent call last):File "<stdin>", line 1, in <module>File "C:\Python34\lib\site-packages\weasyprint\__init__.py", line 337, in <module>
from .html import find_base_url, HTML5_UA_STYLESHEET, get_html_metadata  # noqaFile "C:\Python34\lib\site-packages\weasyprint\html.py", line 41, in <module>
HTML5_UA_STYLESHEET = CSS(filename=os.path.join(root, 'css', 'html5_ua.css'))File "C:\Python34\lib\site-packages\weasyprint\__init__.py", line 224, in __init__
with result as (source_type, source, base_url, protocol_encoding):
File "C:\Python34\lib\contextlib.py", line 59, in __enter__
return next(self.gen)File "C:\Python34\lib\site-packages\weasyprint\__init__.py", line 294, in _select_source
base_url = path2url(filename)File "C:\Python34\lib\site-packages\weasyprint\urls.py", line 87, in path2url
path = pathname2url(path)File "C:\Python34\lib\nturl2path.py", line 46, in pathname2url
if not ':' in p:
TypeError: 'str' does not support the buffer interface
>>>

I get a similar traceback when importing in Python 3.5.1, with the exception of the final TypeError being:

TypeError: a bytes-like object is required, not 'str'

[1] https://gist.github.com/doobeh/3188318

Answer

I had looked through the issues list at weasyprint.org and didn't find anyone else complaining about Python 3.x compatibility with WeasyPrint. Then I happened upon a pull request that did complain about just that and mirrors my difficulties exactly. So off the shelf it does not work with Python 3.x, but with a small hack it does, see [1]. I'll add some comments to the pull request and hopefully this incompatibility will get looked at.

[1] https://github.com/Kozea/WeasyPrint/pull/132

https://en.xdnf.cn/q/118299.html

Related Q&A

matplotlib scatter array lengths are not same

i have 2 arrays like this x_test = [[ 14. 1.] [ 14. 2.] [ 14. 3.] [ 14. 4.] [ 14. 5.] [ 14. 6.] [ 14. 7.] [ 14. 8.] [ 14. 9.] [ 14. 10.] [ 14. 11.] [ 14. 12.]]y_test = [ 254.7 255…

APLpy/matplotlib: Coordinate grid alpha levels for EPS quality figure

In the normal matplotlib axes class, it is possible to set gridlines to have a certain transparency (alpha level). Im attempting to utilise this with the APLpy package using the following:fig = pyplot.…

How to extract word frequency from document-term matrix?

I am doing LDA analysis with Python. And I used the following code to create a document-term matrixcorpus = [dictionary.doc2bow(text) for text in texts].Is there any easy ways to count the word frequen…

Remove only overlapping ticks in subplots grid

I have created a subplots grid without any spaces between the subplots, with shared x,y-axes. I only show the ticks and labels for the outer subplots. The problem is that the tick numbers overlap at th…

how to start a thread when django runserver?

I want to start a thread when django project runserver successfully. where can I put the create-thread-and-start code? Is there any hook for the django runserver?

pandas groupby plot values

I have a pandas dataframe that looks like this:**real I SI weights**0 1 3 0.3 0 2 4 0.20 1 3 0.50 1 5 0.51 2 5 0.3…

Any python module for customized BNF parser?

friends.I have a make-like style file needed to be parsed. The grammar is something like:samtools=/path/to/samtools picard=/path/to/picardtask1: des: descriptionpath: /path/to/task1para: [$global.samto…

How to draw an histogram with multiple categories in python

I am a freshman in python, and I have a problem of how to draw a histogram in python.First of all, I have ten intervals that are divided evenly according to the length of flowers petal, from min to max…

Turtle in Tkinter creating multiple windows

I am attempting to create a quick turtle display using Tkinter, but some odd things are happening.First two turtle windows are being created, (one blank, one with the turtles), secondly, any attempt of…

Array tkinter Entry to Label

Hey Guys I am beginner and working on Project Linear and Binary search GUI application using Tkinter, I want to add multiple Entry boxes values to label and in an array here, I tried but its not workin…