我似乎无法让 WeasyPrint 在 Windows 上使用 Python 3.4 或 3.5 工作。有没有人能够做到这一点?weasyprint.org 上没有论坛,IRC 频道已经死了。
我已经能够使用 Python 3.4.3 和 3.5.1 进行安装。我已遵循此处的指南 [1]。我还注意到 WeasyPrint 的网站声称它应该与 Python 2.6+ 或 3.1+ 一起使用。
当我为 Python 3.4.3 安装并打开 Python shell 并简单地“导入 weasyprint”时,我得到了这个:
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
>>>
在 Python 3.5.1 中导入时,我得到了类似的回溯,除了最终的 TypeError 是:
TypeError: a bytes-like object is required, not 'str'