WeasyPrint usage with Python 3.x on Windows

左心房为你撑大大i 提交于 2019-12-13 05:14:21

问题


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  # noqa
  File "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


回答1:


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://stackoverflow.com/questions/37994733/weasyprint-usage-with-python-3-x-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!