I'm sure you have a good reason for this, however, should you really import a package within a function, let alone within a for loop?
I realise it doesn't actually load it again and again (you would have to reload() it.

My concern is that it is not obvious that you are making use of the package until we route through the code and find it here