【发布时间】:2014-03-31 07:03:01
【问题描述】:
我使用 pip 安装了 xhtml2pdf 以与 Django 一起使用。我收到以下 ImportError:
Reportlab Toolkit Version 2.2 or higher needed
但我有 reportlab 3.0
>>> import reportlab
>>> print reportlab.Version
3.0
我在xhtml2pdf 的__init__.py 中发现了这个try catch 块:
REQUIRED_INFO = """
****************************************************
IMPORT ERROR!
%s
****************************************************
The following Python packages are required for PISA:
- Reportlab Toolkit >= 2.2 <http://www.reportlab.org/>
- HTML5lib >= 0.11.1 <http://code.google.com/p/html5lib/>
Optional packages:
- pyPDF <http://pybrary.net/pyPdf/>
- PIL <http://www.pythonware.com/products/pil/>
""".lstrip()
log = logging.getLogger(__name__)
try:
from xhtml2pdf.util import REPORTLAB22
if not REPORTLAB22:
raise ImportError, "Reportlab Toolkit Version 2.2 or higher needed"
except ImportError, e:
import sys
sys.stderr.write(REQUIRED_INFO % e)
log.error(REQUIRED_INFO % e)
raise
util.py还有另一个错误:
if not (reportlab.Version[0] == "2" and reportlab.Version[2] >= "1"):
不应该是这样的:
if not (reportlab.Version[:3] >="2.1"):
什么给了?
【问题讨论】:
-
您是否在 virtualenv 中使用了旧版本?
-
不。我将它安装在我的 virtualenv 中。上面的控制台输出也来自我的 virtualenv。我的 Django 项目只有一个 virtualenv,安装了最新版本的
reportlab。
标签: python django pip reportlab xhtml2pdf