Re: `import wx` raising `AttributeError`

Matt Newville <[email protected]>
Newsgroups gmane.comp.python.wxpython
Message-ID <CA+7ESbqtq7Us86Fxj2XO-uwknLkXURTfcquG9A41p-Fv_XE-JA@mail.gmail.com>
Hi Mario,

On Thu, Oct 17, 2019 at 6:41 PM Mario Lacunza <[email protected]> wrote:

> Thats not the REAL error, check below from my console:
>
> mario@pc:~$ python3
> Python 3.6.8 (default, Oct  7 2019, 12:59:55)
> [GCC 8.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import wx
> >>> __version__ = wx.__version__.VERSION_STRING
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: 'str' object has no attribute 'VERSION_STRING'
>
>
I think that what my users are reporting *is* a real error that happens on
`import wx`.  To be clear non of their code or my code is doing
`wx.__version__.VERSION_STRING` after `import wx`, which would indeed raise
the AttributeError you see because `wx.__version__` (which is a string) has
no attribute named `VERSION_STRING`.

But, `site-packages/wx/__init__.py` is (abbreviated but complete):

    import wx.__version__

    __version__ = wx.__version__.VERSION_STRING


    from wx.core import *


    del core

    del wx

That will import `wx/__version__.py` , a file which is a very simple set of
assignments and is, as Robin points out, generated at build time.  And then
it will overwrite `__version__` with the string that was the value of
`VERSION_STRING` in `wx/__version__.py`.

The traceback they sent to me shows an AttributeError in which `wx` doesn't
have an attribute `__version__`.
I don't understand how that happens.

Anyway, thanks!

--Matt

-- 
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/CA%2B7ESbqtq7Us86Fxj2XO-uwknLkXURTfcquG9A41p-Fv_XE-JA%40mail.gmail.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.