“如何克服这个pdfviewer”;没有名为“查看器”的模块;wxpython中的错误?

“如何克服这个pdfviewer”;没有名为“查看器”的模块;wxpython中的错误?,python,wxpython,pdfviewer,Python,Wxpython,Pdfviewer,我正在尝试创建一个具有显示pdf文件功能的应用程序,由于pdfviewer类的原因,我决定使用wxpython来实现这一点 我确保我有pyPDF2和pyPdf。(可以使用其中一个,但同时安装两个,以查看这是否是问题所在。) 但是,当我运行底部的代码时。(摘自)(去掉了第31行和第17行的“````。在第16行的.VSCROLL和.SUNKEN_边框之前添加了wx)我得到了消息: Traceback (most recent call last): File "E:\Test\pdf.py",

我正在尝试创建一个具有显示pdf文件功能的应用程序,由于pdfviewer类的原因,我决定使用wxpython来实现这一点

我确保我有pyPDF2和pyPdf。(可以使用其中一个,但同时安装两个,以查看这是否是问题所在。)

但是,当我运行底部的代码时。(摘自)(去掉了第31行和第17行的“````。在第16行的.VSCROLL和.SUNKEN_边框之前添加了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'

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

刚刚发现另一篇文章说wx.lib小部件尚未移植。但那是在2013年。您正在使用哪个版本的wxPython和什么操作系统?因为您似乎正在使用Python3,请测试是否将该行从更改为
。viewer import pdfViewer
修复了导入问题。@MikeDriscoll Windows 8.1希望最后一件事是跨平台。通过降级到2.7.9修复了它。(您的书是否也发往英国?@robindurn它将错误更改为:
SystemError:未加载父模块“”,无法执行相对导入
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()