ModuleWizard.py crash on png file

  1. Following on the HelloCLI tutorial…

  2. Ran the ModuleWizard.py as follows…

/Utilities/Scripts/ModuleWizard.py --template ./Extensions/Testing/CLIExtensionTemplate --target ../My_Module 
My_Module
  1. Then, it crashes with the following error message… It seems like the script cannot handle .png file properly…
creating G:/Libs/slicer/My_Module/My_Module\My_Module.png
Traceback (most recent call last):
  File "g:\Libs\slicer\Slicer\Utilities\Scripts\ModuleWizard.py", line 121, in <module>
    main(sys.argv[1:])
  File "g:\Libs\slicer\Slicer\Utilities\Scripts\ModuleWizard.py", line 115, in main
    copyAndReplace(file, template, target, templateKey, moduleName)
  File "g:\Libs\slicer\Slicer\Utilities\Scripts\ModuleWizard.py", line 38, in copyAndReplace
    contents = fp.read()
  File "C:\Python36\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 154: character maps to <undefined>

Hi -

Thanks for reporting.

To confirm, you were using this tutorial?
https://www.slicer.org/wiki/Documentation/4.6/Training#HelloCLI

It may be that the ModuleWizard script only works with python 2.7 (looks like you are using 3.6). Maybe try that and let us know?

Also the ExtensionWizard is probably a better way now. If you look at this “Developing and Contributing Extensions for 3D Slicer” tutorial you can see how it works. The only difference is that you pick ‘cli’ instead of ‘scripted’ when adding the module to your extension.

https://www.slicer.org/wiki/Documentation/4.6/Training#Developing_and_Contributing_Extensions_for_3D_Slicer

HTH,
Steve

1 Like

Yes, I was using the HelloCLI tutorial of the link.

Just now, I removed python36 and installed python27. The ModuleWizard
script finished without any error, but the png file got corrupted and I
could not open it. I assume…, not 100% sure… me, a python newbie… it
is because the file was open as text file, modified, and saved as text
file… If my assumption is right…, I guess the same is true for all
other binary files (the image files in the Data sub-folder).

Thanks for the link regarding ExtentionWizard. I’ll try it.

Best regards,
Jinkoo

The included .png file is just a placeholder. Replace it with your own icon.