I am developing a dag in Airflow. I am trying to install dependencies by using requirements.txt file.
I run the container in my dev(Windows 11) environment, but dependencies are not installed. I am getting the below error message in Airflow UI:
Broken DAG: [/opt/airflow/dags/my_dag.py] Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/opt/airflow/dags/my_dag.py", line 6, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
I rebuild the docker image by using below commands but it did not work.
docker-compose down
docker-compose build
docker-compose up -d
Requirements.txt file is as below:
pandas
scikit-learn
sqlalchemy
airflow
dbt
matplotlib
Dockerfile is as below:
# Use an official Airflow image as the base image
FROM apache/airflow:2.7.3
# Set the working directory to /usr/src/app
WORKDIR /usr/src/app
# Copy the requirements.txt file into the container at /usr/src/app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Install any needed packages specified in requirements.txt
#RUN pip install --no-cache-dir -r ./requirements.txt
# Make port 8080 available to the world outside this container
EXPOSE 8080
I am expecting to import the below Python libraries in my_dag.py. However, I can not install matplotlib or scikit-learn into the container worker nodes
import matplotlib.pyplot as plt
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression