如何克服 wxpython 中的这个 pdfviewer "No module named viewer" 错误?

How to over come this pdfviewer "No module named viewer" error in wxpython?

我正在尝试创建一个具有显示 pdf 文件功能的应用程序,由于 pdfviewer class.

,我决定使用 wxpython 来执行此操作

我确定我有 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()

这需要一些工作才能让 pdfviewer 在 Py3 上工作,我为此做了 PR。不是 PR 从 pyPDF 切换到 PyPDF2,因为前者不支持 Py3,它还取决于 PR 172 某人为使 PyPDF2 在 Py3 上正常工作所做的工作。