Django-easy-pdf:需安装reportlab 2.2+,但已安装3.0
我正在尝试使用 django-easy-pdf
,但是在安装依赖的时候遇到了问题。
当我运行 Django 时,出现了 ImportError: No module named xhtml2pdf.default
的错误。
为了解决这个问题,我尝试执行 pip install xhtml2pdf
,但是系统提示 Could not find any downloads that satisfy the requirement pyPdf (from xhtml2pdf)
,意思是找不到满足要求的 pyPdf。
于是我决定用 pip install --allow-unverified pyPdf pyPdf
来绕过这个问题。这个命令执行得很顺利。当我再次运行 pip install xhtml2pdf
时,软件顺利安装了。
不过,当我启动 Django 1.6 时,又出现了一个错误:ImportError: Reportlab Version 2.1+ is needed!
。
其实我已经安装了 2.2 或更高版本的 reportlab,因为我用 pip freeze
查看时显示的是 3.0。
看起来这个问题是因为在一些文件里(util.py
和 __init__.py
)硬编码了版本要求:
if not (reportlab.Version[0] == "2" and reportlab.Version[2] >= "1"):
raise ImportError("Reportlab Version 2.1+ is needed!")
if not REPORTLAB22:
raise ImportError, "Reportlab Toolkit Version 2.2 or higher needed"
除了从源代码中删除这些检查,还有什么办法可以解决这个问题吗?
1 个回答
作者在 https://github.com/nigma/django-easy-pdf 上提到:
django-easy-pdf depends on:
django>=1.5.1
git+https://github.com/chrisglass/xhtml2pdf.git
需要安装特定版本,而不是在 pypi 上找到的那个版本。首先,使用 pip uninstall
卸载 xhtml2pdf 和 pypdf,然后执行:
pip install git+https://github.com/chrisglass/xhtml2pdf.git