# ModuleWizard script problems

**URL:** <https://discourse.slicer.org/t/modulewizard-script-problems/24401>\
**Category:** Support\
**Created:** [July 20, 2022, 5:33am UTC](https://discourse.slicer.org/t/modulewizard-script-problems/24401 "2022-07-20T05:33:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![torquil](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@torquil](https://discourse.slicer.org/u/torquil)\
**Post date:** [July 20, 2022, 5:33am UTC](https://discourse.slicer.org/t/modulewizard-script-problems/24401/1 "2022-07-20T05:33:21Z")

</div>

Hi! I’m going to create a new module. I followed a tutorial which told med to download the source code and run the following:

python3 ./Utilities/Scripts/ModuleWizard.py --template ./Extensions/Testing/ScriptedLoadableExtensionTemplate --target …/ModuleName ModuleName

There are two problems. First, it didn’t work with python3:

Will copy  
{template}  
to  
{target}  
replacing “{templateKey}” with “{moduleName}”

[‘CMakeLists.txt’, ‘ScriptedLoadableExtensionTemplate.png’, ‘ScriptedLoadableModuleTemplate/CMakeLists.txt’, ‘ScriptedLoadableModuleTemplate/ScriptedLoadableModuleTemplate.py’, ‘ScriptedLoadableModuleTemplate/Resources/Icons/ScriptedLoadableModuleTemplate.png’, ‘ScriptedLoadableModuleTemplate/Testing/CMakeLists.txt’, ‘ScriptedLoadableModuleTemplate/Testing/Python/CMakeLists.txt’]  
creating …/TorquilTools/CMakeLists.txt  
creating …/TorquilTools/TorquilTools.png  
Traceback (most recent call last):  
File “/home/torquil/Slicer/./Utilities/Scripts/ModuleWizard.py”, line 123, in   
main(sys.argv[1:])  
File “/home/torquil/Slicer/./Utilities/Scripts/ModuleWizard.py”, line 117, in main  
copyAndReplace(file, template, target, templateKey, moduleName)  
File “/home/torquil/Slicer/./Utilities/Scripts/ModuleWizard.py”, line 39, in copyAndReplace  
contents = fp.read()  
File “/usr/lib/python3.10/codecs.py”, line 322, in decode  
(result, consumed) = self.\_buffer\_decode(data, self.errors, final)  
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x89 in position 0: invalid start byte

So I ran this:

python2.7 ./Utilities/Scripts/ModuleWizard.py --template ./Extensions/Testing/ScriptedLoadableExtensionTemplate --target …/ModuleName ModuleName

but this gave the following error:

File “./Utilities/Scripts/ModuleWizard.py”, line 112  
print(f"\nWill copy \n\t{template} \nto \n\t{target} \nreplacing "{templateKey}" with "{moduleName}"\n")  
^  
SyntaxError: invalid syntax

Removing an “f” at the beginning of the print() argument seemed to solve the problem. Is that bug?

Will the script also be updated to work with python3?

Best regards,  
Torquil Sørensen, Norway
