In what order are server modules imported?

I am having some import problems, and I think they are caused by the order the modules are imported.

Is it possible to control the order they are imported?

Hmm… it looks like the first imported module is the first one in alphabetic order.

So, assuming that there is one main module that imports all the others, all I need to do is either to rename that module so it’s first in alphabetical order or create a new module called AAAFirstImportedModule that contains one single line from MainModule import *.

EDIT
I can confirm that creating an AAA module that decides what module is imported first solved the problem.

In my case I was getting this error:
PicklingError: Can't pickle <class 'ShippingCostCalculator.FedexShippingCost.FedexRating'>: it's not the same object as ShippingCostCalculator.FedexShippingCost.FedexRating.

The problem (I think) was caused by FedexShippingCost being the first module in alphabetical order, so being the first one being imported. Then the MainModule was imported, which did import also FedexShippingCost. This caused FedexRating to be… what? Duplicated? I don’t really understand, but, after adding some prints during the input phase, I can now see that FedexShippingCost is imported only once and pickle is now happy to pickle FedexRating.

1 Like