[Tutor] where does the ViewerFrameWorkGUI come from
Walter Prins
wprins at gmail.com
Sun Dec 18 21:28:51 CET 2011
Lina,
On 18 December 2011 05:08, lina <lina.lastname at gmail.com> wrote:
> Hi,
>
> I met below issue:
>
> File "/usr/lib/python2.7/dist-packages/ViewerFramework/VF.py", line
> 369, in __init__
> self.GUI = ViewerFrameworkGUI(self, title=title,
> NameError: global name 'ViewerFrameworkGUI' is not defined
>
>
> can someone tell me how to examine,
>
> I mean, how to examine, what would you do when you face the problem?
You should be telling us what you're doing, what platform you're
using, what packages you've installed and so on, and not be leaving us
to guess these things. It makes our job harder than it would
otherwise be. That said, I've spent only a few minutes to
troubleshoot this and will outline what I did so you can see "what I
did when faced with this problem":
1.) Some googling reveals to me that ViewerFramework/VF.py apparently
forms part of a molecular visualization package called
mgltools-viewerframework.
2.) OK so Installing this package yields the same files in the same
location on my Ubuntu 11.10 box.
3.) Trying to see what was going on, I then when on to inspect the
referenced source file at line 369, where it becomes apparent that the
code is trying instantiate a class ViewerFrameworkGUI.
4.) The question then occurs: Where does this class come from? How is
it that it's not defined? Consequently I started searching for this
class, firstly in the same file, so see where it may be defined or
where it might be imported from.
5.) Doing so I found the following code at line 221 in VF.py:
try:
from ViewerFramework.VFGUI import ViewerFrameworkGUI
except:
pass
"Curious", I thought, how is it that this module can fail to import
this class? And why is it squashing the exception? Generally I would
consider this type of behaviour very undersireable. Far better would
be to stub or mock out the class with a fake that gives some useful
behaviour if it's instantiated (e.g. even if just to give some
sensible error message to the end user...) but perhaps this is a
semi-standard way of stubbing out optional extensions to packages in
Python.
6.) So next I decided to manually replicate the aboev import in the
Python interpreter to see what would happen:
walterp at s1:/usr/lib/python2.7/dist-packages/ViewerFramework$ python
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ViewerFramework.VFGUI import ViewerFrameworkGUI
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/ViewerFramework/VFGUI.py",
line 21, in <module>
import Tkinter, thread, string, Pmw, types
ImportError: No module named Pmw
>>>
"Well then, what's this 'Pmw' that's missing?" I thought to myself. A
quick google later and I found it: http://pmw.sourceforge.net/
7.) OK, so that import will fail with an exception due to Pmw being
missing (if it's not installed), but it'll go unnoticed due to the
exception handler squashing it. This however means that the
ViewerFrameworkGUI class is not always defined, which will cause other
stuff depending on it to fail mysteriously (as you've found.) At this
point, not knowing anything about the packages involved, I'd
tentatively suggest that perhaps the Pmw package should be a
dependency of the mgltools-viewerframework, and it not being might be
an omission/bug in the package. Then again maybe they deliberately
don't want the mgltools-viewerframework package to be neccesarily
dependant on the Pmw package but keep it optional. Whatever the case
is, the bottom line is that you need it in order to solve this
issue...
8.) Knowing that oftentimes python modules are packaged on Debian
based systems (like Ubuntu) as python-xxx I then tried:
sudo apt-get install python-pmw
... and voila, the Pmw module should now be there.
9.) Thus I retried my experiment to manually import ViewerFrameworkGUI
as before:
walterp at s1:/usr/lib/python2.7/dist-packages/ViewerFramework$ python
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ViewerFramework.VFGUI import ViewerFrameworkGUI
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/ViewerFramework/VFGUI.py",
line 22, in <module>
from PIL import Image, ImageTk
ImportError: cannot import name ImageTk
"Hmmm, so now it's not finding the ImageTk class from the PIL library
for some reason" I thought. "Why might that be...?" I checked and I
did in fact have the PIL library already installed, so it wasn't that
PIL wasn't there at all. (This should've been expected since if PIL
wasn't there at all, then presulably importing "Image" would've also
failed...)
A little bit of further googling and I find some evidence that ImageTk
was (for whatever reason) seperated into its own package with the
advent of Python 2.6 (See
http://www.python-forum.org/pythonforum/viewtopic.php?f=4&p=65248 and
https://bugzilla.redhat.com/show_bug.cgi?id=247171 ) and that I should
install the python-imaging-tk package to get the Python module
containing ImageTk.
10.) So I did:
sudo apt-get install python-imaging-tk
This then solved the ImageTk import issue, but left me with more
issues. (I seem to be missing other "mgltools" related packages.) I'm
however not terribly interested in troubleshooting this further on my
box as I've got no use for these things and since what I've posted
should solve your immediate issue and gives you an insight how I
tackled your issue and you may not even have these other issues I'm
going to leave it at that for now.
Walter
More information about the Tutor
mailing list