Suppose I have two versions of a python package, say "lib". One is in folder ~/version1/lib
and the other is in ~/version2/lib
. I'm trying to load both packages in one session by doing this:
sys.path.insert(0, '~/version1')
import lib as a
sys.path.insert(0, '~/version2')
import lib as b
But it doesn't work, because of cache, b
will be the same as a
.
Is there anyway to do it? Maybe use hook in sys.meta_path
? I didn't figure it out.
Or is there anyway to delete cache of imported modules?
You have to import it from one level higher:
import version1.my_lib as a
import version2.my_lib as b
Also make sure that in all the folder there is a __init__.py
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With