We use the following function and it seems to work. The key is deleting all sgtk-related modules from sys.modules and removing TANK_CURRENT_PC from the environment. There was an article about this on the Shotgun website a while back.
def get_sgtk(proj_name, script_name):
""" Load sgtk path and import module
If sgtk was previously loaded, replace include paths and reimport
"""
project_path = get_proj_tank_dir(proj_name)
sys.path.insert(1, project_path)
sys.path.insert(1, os.path.join(
project_path,
"install", "core", "python"
))
# unload old core
for mod in filter(lambda m: m.startswith("sgtk") or m.startswith("tank"), sys.modules):
sys.modules.pop(mod)
del mod
if "TANK_CURRENT_PC" in os.environ:
del os.environ["TANK_CURRENT_PC"]
import sgtk
setup_sgtk_auth(sgtk, script_name)
return sgtk
Overall, I too find it annoying that you cannot use the same toolkit, but there’s all kinds of questions about versioning, etc.