Written by

Sales Engineer at InterSystems
Article Sylvain Guilbaud · Feb 28, 2025 1m read

Avoid to use package named "code" with embedded python methods using [Language = python]

Hello,

as it took me some time to figure out what's wrong, I would like to share this experience, so that you do not fall into the same trap.

I've just noticed that if you name your package "code" (all lowercase), in a class using some embedded python using [Language = python], you'll face the <THROW> *%Exception.PythonException <PYTHON EXCEPTION> 246 <class 'ModuleNotFoundError'>: No module named 'code.basics'; 'code' is not a package

Class code.basics Extends%RegisteredObject
{

ClassMethod Welcome() As%Status [ Language = python ]
{
print('Welcome!')
return True
}
}
IRISAPP>w##class(code.basics).Welcome()

W##CLASS(code.basics).Welcome()
^
<THROW> *%Exception.PythonException <PYTHON EXCEPTION> 246 <class 'ModuleNotFoundError'>: No module named 'code.basics'; 'code' is not a package

It works well with "Code" :

Class Code.basics Extends%RegisteredObject
{

ClassMethod Welcome() As%Status [ Language = python ]
{
print('Welcome!')
return True
}
}
IRISAPP>w##class(Code.basics).Welcome()
Welcome!
1

Comments

Philip Miloslavsky · Mar 4, 2025

Anything that's in python sys.modules (plenty of other examples) isn't likely to work very well because of the way the namespaces are merged.

0