I have two versions of the same package with the following structure:
pkgs
├── v1
│   ├── pkg
│   │   ├── main.py
│   │   └── utils.py
│   └── setup.py
└── v2
    ├── pkg
    │   ├── main.py
    │   └── utils.py
    └── setup.py
I want to first use function from v1 main.py and then use the same function but from v2 main.py.
I can't import pkg by path since it imports another function from utils.py using import pkg.utils, so pkg have to be installed.
I tried reinstalling the package using pip and reloading:
import pkg
subprocess.check_call([sys.executable, "-m", "pip", "install", "--quiet", "pkgs/v2"])
pkg = reload(pkg)
that doesn't work, the python reloads v1 version.
Is there a way to make this work?
EDIT: Code example:
    subprocess.check_call([sys.executable, "-m", "pip", "uninstall", "--quiet", "-y", module_name])
    subprocess.check_call([sys.executable, "-m", "pip", "install", "--quiet", "-e", pkg_dir])
    importlib.invalidate_caches()
    module = importlib.import_module(module_name)
    pkgfunc = getattr(module, "func")
