没有名为main的模块,wkhtmltopdf问题

时间:2015-04-09 08:10:43

标签: python wkhtmltopdf

我是python的新手,但我找到的所有搜索结果对我来说都没用。

    C:\Users\Aero>pip install wkhtmltopdf
Collecting wkhtmltopdf
  Using cached wkhtmltopdf-0.2.tar.gz
Installing collected packages: wkhtmltopdf
  Running setup.py install for wkhtmltopdf
Successfully installed wkhtmltopdf-0.2

C:\Users\Aero>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 wkhtmltopdf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\site-packages\wkhtmltopdf\__init__.py", line 1, in <module>
    from main import WKhtmlToPdf, wkhtmltopdf
ImportError: No module named 'main'

这种情况一直在发生。谢谢你的帮助。

更新
我发现安装Python 2. *可以使main模块在​​使用print(使用2. *版本)时不正确。 但我仍然想知道,有什么方法吗?

4 个答案:

答案 0 :(得分:3)

我解决了这种安装方式,希望它对您有用

pip install django-wkhtmltopdf

答案 1 :(得分:1)

这是第一次不适合我,但是在PyCharm重启后我可以看到任何东西。这可能适合你:(在Python 3.3.0上测试)

import wkhtmltopdf
from wkhtmltopdf.main import WKhtmlToPdf

var = WKhtmlToPdf(
    url='http://www.example.com',
    output_file='~/example.pdf',
)
var.render()

答案 2 :(得分:0)

似乎wkhtmltopdf的软件包安装有一些错误。这对我不起作用然后我卸载了包并通过执行

重新安装它
python -m pip uninstall wkhtmltopdf

然后

python -m pip install wkhtmltopdf

它对我有用。这可能有用。

答案 3 :(得分:0)

如果其他任何选项均无效,则可能是您的缓存有问题。尝试卸载wkhtmltopdf和django-wkhtmltopdf并在没有缓存的情况下重新安装:

pip uninstall django-wkhtmltopdf wkhtmltopdf
pip install --no-cache-dir wkhtmltopdf==0.2
pip install --no-cache-dir django-wkhtmltopdf==3.2.0

(请注意,上述wkhtmltopdf和django-wkhtmltopdf版本号可能会有所不同。)