cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to use bundle substitutions in %pip install for Lakeflow Declarative Pipelines

ChrisLawford_n1
Contributor

Hello,

When defining a Lakeflow Declarative Pipeline (DLT pipeline) I would like to allow the installation of a whl file to be dictated by the user running the pipeline. This will allow the notebook to have the pip installs at the top be agnostic of the developer deploying the bundle. W

Currently we have something like:
%pip install /Workspace/Users/a5ddafef-XXXX-XXXX-XXXX-a34e1c6acda0/.bundle/ADP/developer/artifacts/.internal/adp-0.1.0-py3-none-any.whl
What I would ideally like is:
%pip install ${workspace.root_path}/artifacts/.internal/adp-0.1.0-py3-none-any.whl

But you cant get the bundle substitutions inside the notebooks themselves from what I have read. I have tried to use dbutils.widgets to first get a passed in parameter and use that in the pip install.
This doesn't work in DLT pipelines though as you can't have any code above the %pip install line.
#lakeflowdeclarativepipelines #dlt #pip

1 ACCEPTED SOLUTION

Accepted Solutions

BigRoux
Databricks Employee
Databricks Employee

Some considerations:

 

There is currently no fully supported, user-driven way to inject dynamic or parameterized .whl file installation paths directly into Databricks Lakeflow Declarative (DLT) pipeline notebooks, such that %pip install can reference bundle substitution variables (like ${workspace.root_path}) at notebook execution time.

Key Insights from Research

  • DLT Pipelines and %pip install:
    • The recommended method to add Python dependencies in DLT is via %pip install at the top of notebooks.
    • DLT executes all %pip install cells before running any other notebook code, which means you cannot use dbutils.widgets or variables set in code cells to drive the installation path.
    • Relative paths do not work for DLT notebook execution, as the DLT runtime does not set the current working directory to the notebook location. You must use absolute workspace paths for %pip install.
  • Bundle Substitution Variables:
    • Databricks Asset Bundles (DAB) support powerful variable substitution in bundle configuration files (YAML) – for example, constructing resource file paths based on ${workspace.root_path}, ${bundle.target}, etc., for jobs and pipelines.
    • These substitutions enable configuring deployments in a user/environment-agnostic way at deploy time, but they are not expanded inside notebook content. That is, referencing ${workspace.root_path} in notebooks is not supported for runtime cell execution.
    • As such, you cannot use bundle variable syntax within a notebook cell for the %pip install command.
  • Common Workarounds and Limitations:
    • Some have tried using dbutils.widgets or other notebook-driven parameters to make the whl path dynamic, but this is not viable since no code can precede %pip install lines, and widget values cannot be parsed before install.
    • Other approaches, like using requirements.txt or environments, are being actively developed for DLT pipelines (“environments for pipelines” is mentioned in ongoing product engineering work). If and when this is fully released, it may enable parameterized dependency injection but is not yet generally available.
  • Possible Practices:
    • The current best practice is to predefine the absolute path to the .whl file (such as /Workspace/Shared/code/...) and ensure it is consistent across users and environments. The path must be hardcoded in the notebook if using %pip install in DLT pipelines.
    • If the wheel file’s location can be standardized (e.g., via CI/CD pipelines, always uploading to the same Shared location), this at least decouples it from user home directories and individual developer context.

No Supported Dynamic In-Notebook Path Substitution

There is no way to use bundle substitutions or dynamic parameters inside DLT notebooks for the %pip install command at this time. All such substitutions are resolved at the bundle deployment (YAML) layer and do not propagate as runtime variables inside notebooks.

Summary Table

Mechanism DLT %pip Supported Bundle Variable Expansion User/Env Agnostic
%pip install ${workspace.root_path}/... Yes No No
Hardcode absolute path in Shared/ location Yes Not needed Partially
dbutils.widgets/any-variable before %pip No N/A N/A
requirements.txt / environment spec (future) Not yet N/A Not yet

Guidance

  • Use a shared, standardized location for .whl files in your workspace, and install via absolute path in %pip install.
  • Stay alert for future Databricks releases that add support for environments in DLT, which may address this limitation.
If strict user-based path selection is absolutely required today, consider moving to Jobs with custom environment handling, or orchestrate deployment of the .whl into a known shared workspace path as part of your CI/CD pipeline so the %pip install path is stable and user-agnostic.
 
In summary: Databricks currently does not support user-parameterized or bundle-variable-driven %pip install paths inside DLT pipeline notebooks. The only stable solution is to predefine a well-known installation path for your wheel.
 
Hope this helps, Lou.

View solution in original post

3 REPLIES 3

BigRoux
Databricks Employee
Databricks Employee

Some considerations:

 

There is currently no fully supported, user-driven way to inject dynamic or parameterized .whl file installation paths directly into Databricks Lakeflow Declarative (DLT) pipeline notebooks, such that %pip install can reference bundle substitution variables (like ${workspace.root_path}) at notebook execution time.

Key Insights from Research

  • DLT Pipelines and %pip install:
    • The recommended method to add Python dependencies in DLT is via %pip install at the top of notebooks.
    • DLT executes all %pip install cells before running any other notebook code, which means you cannot use dbutils.widgets or variables set in code cells to drive the installation path.
    • Relative paths do not work for DLT notebook execution, as the DLT runtime does not set the current working directory to the notebook location. You must use absolute workspace paths for %pip install.
  • Bundle Substitution Variables:
    • Databricks Asset Bundles (DAB) support powerful variable substitution in bundle configuration files (YAML) – for example, constructing resource file paths based on ${workspace.root_path}, ${bundle.target}, etc., for jobs and pipelines.
    • These substitutions enable configuring deployments in a user/environment-agnostic way at deploy time, but they are not expanded inside notebook content. That is, referencing ${workspace.root_path} in notebooks is not supported for runtime cell execution.
    • As such, you cannot use bundle variable syntax within a notebook cell for the %pip install command.
  • Common Workarounds and Limitations:
    • Some have tried using dbutils.widgets or other notebook-driven parameters to make the whl path dynamic, but this is not viable since no code can precede %pip install lines, and widget values cannot be parsed before install.
    • Other approaches, like using requirements.txt or environments, are being actively developed for DLT pipelines (“environments for pipelines” is mentioned in ongoing product engineering work). If and when this is fully released, it may enable parameterized dependency injection but is not yet generally available.
  • Possible Practices:
    • The current best practice is to predefine the absolute path to the .whl file (such as /Workspace/Shared/code/...) and ensure it is consistent across users and environments. The path must be hardcoded in the notebook if using %pip install in DLT pipelines.
    • If the wheel file’s location can be standardized (e.g., via CI/CD pipelines, always uploading to the same Shared location), this at least decouples it from user home directories and individual developer context.

No Supported Dynamic In-Notebook Path Substitution

There is no way to use bundle substitutions or dynamic parameters inside DLT notebooks for the %pip install command at this time. All such substitutions are resolved at the bundle deployment (YAML) layer and do not propagate as runtime variables inside notebooks.

Summary Table

Mechanism DLT %pip Supported Bundle Variable Expansion User/Env Agnostic
%pip install ${workspace.root_path}/... Yes No No
Hardcode absolute path in Shared/ location Yes Not needed Partially
dbutils.widgets/any-variable before %pip No N/A N/A
requirements.txt / environment spec (future) Not yet N/A Not yet

Guidance

  • Use a shared, standardized location for .whl files in your workspace, and install via absolute path in %pip install.
  • Stay alert for future Databricks releases that add support for environments in DLT, which may address this limitation.
If strict user-based path selection is absolutely required today, consider moving to Jobs with custom environment handling, or orchestrate deployment of the .whl into a known shared workspace path as part of your CI/CD pipeline so the %pip install path is stable and user-agnostic.
 
In summary: Databricks currently does not support user-parameterized or bundle-variable-driven %pip install paths inside DLT pipeline notebooks. The only stable solution is to predefine a well-known installation path for your wheel.
 
Hope this helps, Lou.

ChrisLawford_n1
Contributor

Hey Lou,
Thanks for clarifying and for the swift response. Though nothing you said was news to me it was beneficial to have you confirm that what I am asking for is currently not possible and your alternative is currently what we are doing 🙂 

Thanks,
Chris

BigRoux
Databricks Employee
Databricks Employee

Glad to help and feel free to "Accept as Solution" to help others in the same boat 🙂 Cheers, Lou.

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now