[chimera-dev] Importing modules causes crashes

Greg Couch gregc at cgl.ucsf.edu
Thu May 23 11:11:47 PDT 2013


Hi Mateusz,

Unfortunately that error message hides where the error actually occurred 
because it can't form the error message.
But presumably you've put in print statements to sys.stderr and have 
bracketed the exact location where the problem happens.

Once you identify the exact location, the UnicodeDecodeError indicates 
that you were using a string instead of a unicode string.  If your 
string only contains ASCII characters, that is fine.  If not, it needs 
to have a UTF-8 encoding, or you need to use a unicode string. ( See 
http://docs.python.org/2/howto/unicode.html for details about unicode 
strings in Python 2.)

For example, if your string has a Polish encoding, a.k.a. ISO/IEC 
8859-2, then to get the unicode equivalent:

     unicode_string = string.decode('iso 8859-2')

<http://docs.python.org/2/howto/unicode.html>How you know what encoding 
to use depends on how the string was obtained.  Since the character that 
couldn't be decoded in the error message corresponds to a letter in your 
name, you might be able to fix this bug by adding the proper encoding 
comment at the top of your .py file and using a unicode string constant 
whenever that character is used in a string.

To fix the error reporting (this change will be in the next 1.8 release 
candidate and the daily build), I'm adding the following two lines to 
.../lib/site-packages/Pmw/Pmw_1_3/lib/PmwBase.py:

     if not isinstance(exc_value, unicode):
        exc_value = exc_value.decode('utf-8', 'replace')

Just before the line:

     msg = msg + u'%s: %s\n' % (exc_type, exc_value)

as seen in the traceback in your screen shot.  FYI, on Windows, to get 
the text of the debug window instead of doing a screen shot, you 
right-click on the title bar and use the Edit submenu to Select All and 
Copy the text.

     HTH,

     Greg

On 05/23/2013 09:44 AM, Mateusz Dobrychłop wrote:
> Hello,
>
> I'm writing a Chimera extension that uses modules that it imports an 
> external module.
>
> To do this, I append the sys.path with a path to the directory where 
> the module is placed and then I just import it. And then Chimera crashes.
>
> The line with the import is the one that directly causes the crash.
>
> I'm attaching a screenshot of the error that Chimera throws when I run 
> it with --debug option. I have no idea what might be wrong.
>
> Thank you for your time,
> Mateusz
>
>
> _______________________________________________
> Chimera-dev mailing list
> Chimera-dev at cgl.ucsf.edu
> http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-dev/attachments/20130523/4fd4d3dc/attachment.html>


More information about the Chimera-dev mailing list