在Windows上使用Python 3.x的WeasyPrint使用 [英] WeasyPrint usage with Python 3.x on Windows

查看:190
本文介绍了在Windows上使用Python 3.x的WeasyPrint使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法让WeasyPrint在使用Python 3.4或3.5的Windows上运行.有没有人能够做到这一点? weasyprint.org上没有论坛,并且IRC频道已死.

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.

我已经能够同时使用Python 3.4.3和3.5.1进行安装.我遵循了此处的指南[1].我还注意到WeasyPrint的网站声称它应该与Python 2.6+或3.1+一起使用.

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+.

当我为Python 3.4.3安装并打开Python shell并简单地导入weasyprint"时,我得到了:

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
>>>

在Python 3.5.1中导入时,我得到了类似的回溯,但最终的TypeError是:

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

推荐答案

我浏览了weasyprint.org上的问题列表,没有发现其他人抱怨Python 3.x与WeasyPrint的兼容性.然后,我碰到一个拉扯请求,确实对此有所抱怨,并准确地反映了我的困难.因此,现成的它在Python 3.x中不起作用,但是通过一个小技巧它就可以了,请参阅[1].我将在pull请求中添加一些注释,希望可以解决这种不兼容问题.

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

这篇关于在Windows上使用Python 3.x的WeasyPrint使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆