The problem I’m having
I have boto3 installed in my virtual env but when I run dbt, it cannot find it
I am using dbt-core
pip install dbt-core dbt-snowflake
When running pip freeze | grep dbt
I get
dbt-adapters==1.10.3
dbt-common==1.13.0
dbt-core==1.8.9
dbt-extractor==0.5.1
dbt-semantic-interfaces==0.5.1
dbt-snowflake==1.8.4
The context of why I’m trying to do this
I have a script in my dbt run which requires boto3 , the python script return a df which needs to be written to a table in snowflake
What I’ve already tried
I have confirmed that boto3 exists in the ve
I have confirmed that the dbt run uses the ve, I don’t have a system wide dbt-core installed, it only works when I am in the ve.
I can see the package boto3 and dbt only when in the ve
. ve/bin/active
python
import boto3
- imports fine
exit()
dbt run
Both of these also confirms the ve is being used
which python
which dbt
Everything else works fine, it just cannot find the other packages I installed specific to this VE
I added this to the dbt_project.yml as test
on-run-start:
- "{{ log('Python Executable: ' ~ dbt.flags.PYTHON_EXECUTABLE, info=True) }}"
- "{{ log('Boto3 available: ' ~ ('boto3' in modules), info=True) }}"
Python Executable
prints nothing
Boto3 available
prints false
if I try dbt run
when not in the ve I get command not found: dbt
as expected
I have tried setting the PYTHONPATH to the ve’s python, but it still does the same
I have recreated the ve from scratch and still doesn’t work
Some example code or error messages
100357 (P0000): Python Interpreter Error:
Traceback (most recent call last):
File "_udf_code.py", line 13, in <module>
import boto3
ModuleNotFoundError: No module named 'boto3'```
Additional things I tried
I found some other documentation and I tried that as well
Added this to my python file and also added the models/config.yml
def model(dbt, session):
dbt.config(
materialized="incremental",
packages=["boto3==1.35.72", "botocore==1.35.72"]
)
This had a new error
100357 (P0000): Cannot create a Python function with the specified packages. Please check your packages specification and try again.
compiled code at target/run/metrics/models/metrics_enquiries.py
01:08:59
01:08:59 Done. PASS=1 WARN=0 ERROR=2 SKIP=0 TOTAL=3