我使用xhtml2pdf安装了pip,以便与Django一起使用。我得到了以下ImportError:
Reportlab Toolkit Version 2.2 or higher needed但我有报告3.0
>>> import reportlab
>>> print reportlab.Version
3.0我在__init__.py of xhtml2pdf中找到了这个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)
raiseutil.py中还有另一个错误
if not (reportlab.Version[0] == "2" and reportlab.Version[2] >= "1"):那不应该是这样的吗:
if not (reportlab.Version[:3] >="2.1"):怎么回事?
发布于 2014-02-27 18:23:25
在util.py中,编辑以下行:
if not (reportlab.Version[0] == "2" and reportlab.Version[2] >= "1"):
raise ImportError("Reportlab Version 2.1+ is needed!")
REPORTLAB22 = (reportlab.Version[0] == "2" and reportlab.Version[2] >= "2")并设定为:
if not (reportlab.Version[:3] >="2.1"):
raise ImportError("Reportlab Version 2.1+ is needed!")
REPORTLAB22 = (reportlab.Version[:3] >="2.1")编辑
虽然上面的方法有效,但它仍然使用字符串文本进行版本检查。在xhtml2pdf项目中有一个拉请求,它提供了一个比较使用整数元组的版本的更优雅的解决方案。这是拟议的解决办法:
_reportlab_version = tuple(map(int, reportlab.Version.split('.')))
if _reportlab_version < (2,1):
raise ImportError("Reportlab Version 2.1+ is needed!")
REPORTLAB22 = _reportlab_version >= (2, 2)https://stackoverflow.com/questions/22075485
复制相似问题