Using sgtk module with distributed config

I am using a distributed pipeline configuration, but I would like to use sgtk in Python, for example to generate filesystem paths.

How do I initialize sgtk properly when I am not importing it from a standard centralized setup? For example, i get this error:

tank.util.errors.UnresolvableCoreConfigurationError: Cannot resolve the core 
configuration from the location of the Sgtk Code! This can happen if 
you try to move or symlink the Sgtk API. The Sgtk API is currently picked up 
from /path/to/sgtk/0.21.6/python/tank which is an invalid location.

How can I make SGTK work without the actual SGTK code existing in some special place? Thank you!

I figured this out on my own, but thought this might help people. You need to use the Bootstrap API described here: Initialization and startup — tk-core v0.21.6 documentation

Here’s an example of using it, modified from their example to include specifying an exact pipeline configuration to use.

# Start up a Toolkit Manager
mgr = tank.bootstrap.ToolkitManager()

# Specify the exact pipeline configuration to use here.
mgr.pipeline_configuration = 35

# Set the base configuration to the default config
# Note that the version token is not specified, meaning that
# the latest version will be looked up and used
mgr.base_configuration = "sgtk:descriptor:app_store?name=tk-config-basic"

# Each bootstrap session is normally defined by a plugin id. We recommend
# using a 'basic.' prefix if you want your bootstrap session to pick up the
# standard toolkit configurations
mgr.plugin_id = "basic.my_toolkit_plugin"

e = mgr.bootstrap_engine("tk-shell", entity={'type': 'Project', 'id': PROJECT_ID})

tk: tank.api.Sgtk = e.sgtk

# Now you can do stuff with tk.
1 Like