I have several different repositories from which I need to programmatically import a package with a common name, say my_package
, e..g /foo/bar/my_package
and /foo/baz/my_package
. I need to be able to retrieve my_package
from these different repositories and keep them in separate variables.
I've tried to do this with importlib.import_module
but it just does not work - I end up with the same package variable.
os.chdir('/foo/bar')
foobar_my_package = importlib.import_module('my_package')
os.chdir('/foo/baz')
foobaz_my_package = importlib.import_module('my_package')
> foobar_my_package == foobaz_my_package
> True
I don't understand why this is happening.