姜戈> xhtml2pdf >让它发挥作用吗?
我在理解如何安装 xhtml2pdf 时遇到问题。我已按照 Chris Glass 站点上的说明进行操作,并设置了虚拟环境并运行了单元测试。当我在 views.py
文件顶部插入以下内容时:
import ho.pisa as pisa
import cStringIO as StringIO
import cgi
import os
我收到一条错误消息 No module named ho.pisa
(这是我所期望的)。我如何让 django 甚至 python 命令行导入此模块(因为我已经尝试在命令行中导入该模块并取得相同程度的成功)。
编辑
为什么我需要虚拟环境。我不能将 xhtml2pdf 作为包安装并正常导入吗?或者我会破坏一些 Django/python 的东西吗?
编辑
我还从 xhtml2pdf 虚拟环境中运行 django > (xhtml2pdfenv)person@person-laptop:~/Software/django$ ./manage.py runserver
但它仍然拒绝导入 xhtm2pdf
I'm having problems understanding how I should install xhtml2pdf. I have followed the instructions at Chris Glass's site and have a virtual environment setup and have run unit tests. When I insert the following at the top of my views.py
file:
import ho.pisa as pisa
import cStringIO as StringIO
import cgi
import os
I get an error saying No module named ho.pisa
(which I expected). How do I get django or even the python command line import this module (because I have tried importing the module in the command line with the same level of success).
EDIT
Why do I need a virtual enviroment. Can't I just install xhtml2pdf
as a package and import it normally or will I break some Django/python thing?
EDIT
I have also run django from inside the xhtml2pdf virtual enviroment > (xhtml2pdfenv)person@person-laptop:~/Software/django$ ./manage.py runserver
and still it refuses to import xhtm2pdf
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我只是尝试使用 pip 安装 xhtml2pdf,而不是包。
pisa
模块位于xhtml2pdf
中,而不是ho
I just tried installing xhtml2pdf using pip, not the package.
The
pisa
module was inxhtml2pdf
, notho
我会尝试 virtualenv 和 django 的其他库 或从 http://pypi.python.org/pypi/pisa/
I'd try virtualenv and additional libraries for django or install from http://pypi.python.org/pypi/pisa/
正确的。我通过在 Chris Glass 网站上的开发环境中执行以下第 5 步后使其工作:
导入行
from xhtml2pdf import pisa
inviews.py
不再引发任何错误Right. I got it to work by doing the following after step 5 of the development enviroment at Chris Glass's site:
The import line
from xhtml2pdf import pisa
inviews.py
does not raise any errors any more您可以通过以下行安装 pisa:
You can install pisa by following line: