Search code examples
pythonpython-2.7wxpython

WxPython: Importing wx.lib


I am attempting to import wx.lib when I do

import wx
wx.lib
# I get
AttributeError: 'module' object has no attribute 'lib'

However if I do

import wx.lib
wx.lib

Why does this happen? I would expect when importing wx it would also import the packages below it.


Solution

  • Importing a package does not automatically import sub-packages, unless the package itself do it for you.

    • wx package only imports wx._core. (wxPython 3.0); you need to import wx.lib manually.

    BTW, wx/__init__.py defines __all__ with ['build', 'lib', ...]. You can do this:

    >>> from wx import *  # affected by `__all__`
    >>> lib
    <module 'wx.lib' from '/usr/lib/.../wx-3.0-gtk2/wx/lib/__init__.pyc'>