Forum: Poser - OFFICIAL


Subject: Matmatic/Parmatic and python sys.path OR where to put matmatic script "modules"

an0malaus opened this issue on Nov 25, 2011 ยท 8 posts


millighost posted Fri, 25 November 2011 at 9:34 AM

Quote - ...

So, it seems for simple python modules (filename = module name + .py) which contain all their code in one file, just executing the .py is enough to add its path automatically to sys.path and allow everything to be found.

For python packages, however, executing a python script within the package directory itself doesn't seem to be sufficient for python to locate the package. Python needs to have the parent directory which contains the package (directory) added to the sys.path.

Yes, this is essentially true, but not the whole truth; python, when importing modules, does not only look within the sys.path, but it looks in the path the currently active module was loaded from, too. So in general you can indeed just simply switch to the directory, where the module is in, and then import it. In the special case of parmatic, however, this does not work, because the parmatic module is "self aware", so to speak. I.e. it contains a statement like "from parmatic import ParmaticActor", where a "import ParmaticActor" would normally suffice. Not directly a bug, but an inconvenience that could likely be fixed in an update (ask bagginsbill).

In general, there are two kinds of modules: a) files and b) directories containing an init.py file. The general rule holds: the sys.path must contain the module to load (can be either the directory or the file). Looking at it this way, there is not much difference between modules in packages or modules in files IMO.