如何在wxpython中找到这个pdfviewer“没有模块命名的查看器”错误?

时间:2015-04-13 10:01:15

标签: python wxpython pdfviewer

我正在尝试创建一个具有显示pdf文件功能的应用程序,并决定使用wxpython来执行此操作,因为pdfviewer类。

我确定我有pyPDF2和pyPdf。 (既可以使用,也可以同时安装,以查看是否存在问题。)

然而,当我在底部运行代码时。 (摘自here)(摆脱了第31和17行的```。在第16行的.VSCROLL和.SUNKEN_BORDER之前添加了wx)我收到了消息:

Traceback (most recent call last):
  File "E:\Test\pdf.py", line 4, in <module>
    from wx.lib.pdfviewer import pdfViewer, pdfButtonPanel
  File "C:\Python34\lib\site-packages\wx\lib\pdfviewer\__init__.py", line 124, in <module>
    from viewer import pdfViewer
ImportError: No module named 'viewer'

当我转到该包文件以确认模块查看器在那里时,我然后运行它并且第124行工作。它只是在运行这个示例文件时不起作用,我认为该文件与我的应用程序中的文件相同。

有谁知道我需要做些什么来解决这个问题。该模块看起来非常适合我的计划。

由于

import wx
import wx.lib.sized_controls as sc

from wx.lib.pdfviewer import pdfViewer, pdfButtonPanel

class PDFViewer(sc.SizedFrame):
    def __init__(self, parent, **kwds):
        super(PDFViewer, self).__init__(parent, **kwds)

        paneCont = self.GetContentsPane()
        self.buttonpanel = pdfButtonPanel(paneCont, wx.NewId(),
                                wx.DefaultPosition, wx.DefaultSize, 0)
        self.buttonpanel.SetSizerProps(expand=True)
        self.viewer = pdfViewer(paneCont, wx.NewId(), wx.DefaultPosition,
                                wx.DefaultSize,
                                wx.HSCROLL|wx.VSCROLL|wx.SUNKEN_BORDER)
        self.viewer.UsePrintDirect = False
        self.viewer.SetSizerProps(expand=True, proportion=1)

        # introduce buttonpanel and viewer to each other
        self.buttonpanel.viewer = self.viewer
        self.viewer.buttonpanel = self.buttonpanel


if __name__ == '__main__':
    import wx.lib.mixins.inspection as WIT
    app = WIT.InspectableApp(redirect=False)


    pdfV = PDFViewer(None, size=(800, 600))
    pdfV.viewer.UsePrintDirect = False
    pdfV.viewer.LoadFile(r'a path to a .pdf file')
    pdfV.Show()

    app.MainLoop()

1 个答案:

答案 0 :(得分:0)

这需要一些工作才能让pdfviewer在Py3上运行,我为它做了PR。不是PR从pyPDF切换到PyPDF2,因为前者不支持Py3,它还依赖于PR 172,有人已经做了让PyPDF2在Py3上正常工作。