I follow the example from the best answer here to a T, compiling with Pyc.py.
Build Python scripts and call methods from C#
I get an exception at pyScope = pyEngine.ImportModule("MyClass");
no module named MyClass
I believe this to be a bug as sometimes recompilation with Pyc.py will produce a dll ImportModule recognizes, but other times it doesn’t.
CONCLUSION: As noted below by digEmAll, compiling modules with Pyc.py to be used in this fashion produces random results. Call clr.CompileModules manually instead.
OK,
I got it.
The module name is the (case sensitive) name of the original .py module, not the compiled dll.
I mean, if your original module name was
myClass.py, then you compiled it inMyClass.dll, you mustImportModule("myClass")notImportModule("MyClass")EDIT:
the previous code refers to the following compile method:
On the contrary, using
pyc.py, the generated dll contains a module called__main__instead of the.pyfile name.That’s very strange…
IIRC, in python a module call itself
__main__if it’s running standalone (i.e. not called by another), but I still don’t grasp the connection…