duckdb / dbt-duckdb

dbt (http://getdbt.com) adapter for DuckDB (http://duckdb.org)
Apache License 2.0
935 stars 89 forks source link

Not able to import python packages in dbt-duckdb python model #330

Closed nehiljain closed 9 months ago

nehiljain commented 9 months ago

I am trying to build my first python model. I want to use a bunch of python modules. I have them installed in the virtualenv where I am running dbt run.

My code for the dbt model is:

import pendulum

def model(dbt, session):
    df = dbt.ref("hotel_prices")
    #... othr logic
    now = pendulum.now('UTC')
    df['run_date'] = now.to_date_string()
    df['run_at'] = now.to_datetime_string()
    return df

But at runtime, the pendulum is missing.

Is there an example on how to use module_path or documentation of how to import libraries for running these models?

jwills commented 9 months ago

So Python path stuff can be a little tricky to figure out-- did you install dbt-duckdb into the same venv?

In terms of examples, I use the module_paths stuff in this repo for loading custom UDFs and what not, but those are from custom modules-- i.e., things that aren't pip installed in a venv or whatever.

jwills commented 9 months ago

Like the macro thing that I suspect is going on is that your dbt install is using a Python path that is not/does not match the one that your virtual environment is using to install e.g. pendulum, i.e., your issue is this one: https://stackoverflow.com/questions/76021034/facing-problem-with-dbt-duckdb-adapter-due-incompatible-issue-with-dbt-core

nehiljain commented 9 months ago

Yep, I was doing something stupid. Found the problem. It was related to the paths being different. Thanks @jwills

jwills commented 9 months ago

Anytime— good luck with your project!