Apache airflow: No module name ‘airflow’. Task failed

I installed Airflow by docker according to this video. (Windows+WSL+Ubuntu+Docker)

I have my_dag.py file (replaced APIKEY):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime
import pandas as pd
def _read_api_data():
x1 = requests.get('http://api.openweathermap.org/data/2.5/weather?q=London&appid=APIKEY')
x2 = requests.get('http://api.openweathermap.org/data/2.5/weather?q=Moscow&appid=APIKEY')
responses = [x1, x2]
output_object = {"responses": []}
for x in responses:
json_object = x.json()
output_object["responses"].append(json_object)
json_str = json.dumps(output_object, indent=4)
# Writing to weather_data.json
with open("/tmp/weather_data.json", "w") as outfile:
outfile.write(json_str)
def _download_data():
with open('/tmp/weather_data.json') as f:
d = json.load(f)
responses = d["responses"]
temps_K = [round(r["main"]["temp"] - 273.15, 2) for r in responses]
names = [r["name"] for r in responses]
df = pd.DataFrame({"names": names, "temps_K": temps_K})
return df
def _process_data(ti):
df = ti.xcom_pull(task_ids="download_data")
df["temps_C"] = round(temps["temps_K"] - 273.15, 2)
df.to_csv('/tmp/processed_weather_data.csv')
return df
def _save_data(ti):
df = ti.xcom_pull(task_ids="process_data")
df.to_parquet('/tmp/weather.parquet')
with DAG("weather_data_pipeline_dag",
schedule_interval="@once",
start_date=datetime(2024,7,14)) as dag:
taskPython0 = PythonOperator(
task_id = "read_api_data",
python_callable = _read_api_data
)
taskPython1 = PythonOperator(
task_id = "download_data",
python_callable = _download_data
)
taskPython2 = PythonOperator(
task_id = "process_data",
python_callable = _process_data
)
taskPython3 = PythonOperator(
task_id = "save_data",
python_callable = _save_data
)
taskPython0 >> taskPython1 >> taskPython2 >> taskPython3
</code>
<code>from airflow import DAG from airflow.operators.python import PythonOperator from datetime import datetime import pandas as pd def _read_api_data(): x1 = requests.get('http://api.openweathermap.org/data/2.5/weather?q=London&appid=APIKEY') x2 = requests.get('http://api.openweathermap.org/data/2.5/weather?q=Moscow&appid=APIKEY') responses = [x1, x2] output_object = {"responses": []} for x in responses: json_object = x.json() output_object["responses"].append(json_object) json_str = json.dumps(output_object, indent=4) # Writing to weather_data.json with open("/tmp/weather_data.json", "w") as outfile: outfile.write(json_str) def _download_data(): with open('/tmp/weather_data.json') as f: d = json.load(f) responses = d["responses"] temps_K = [round(r["main"]["temp"] - 273.15, 2) for r in responses] names = [r["name"] for r in responses] df = pd.DataFrame({"names": names, "temps_K": temps_K}) return df def _process_data(ti): df = ti.xcom_pull(task_ids="download_data") df["temps_C"] = round(temps["temps_K"] - 273.15, 2) df.to_csv('/tmp/processed_weather_data.csv') return df def _save_data(ti): df = ti.xcom_pull(task_ids="process_data") df.to_parquet('/tmp/weather.parquet') with DAG("weather_data_pipeline_dag", schedule_interval="@once", start_date=datetime(2024,7,14)) as dag: taskPython0 = PythonOperator( task_id = "read_api_data", python_callable = _read_api_data ) taskPython1 = PythonOperator( task_id = "download_data", python_callable = _download_data ) taskPython2 = PythonOperator( task_id = "process_data", python_callable = _process_data ) taskPython3 = PythonOperator( task_id = "save_data", python_callable = _save_data ) taskPython0 >> taskPython1 >> taskPython2 >> taskPython3 </code>
from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime
import pandas as pd

def _read_api_data():
    x1 = requests.get('http://api.openweathermap.org/data/2.5/weather?q=London&appid=APIKEY')
    x2 = requests.get('http://api.openweathermap.org/data/2.5/weather?q=Moscow&appid=APIKEY')

    responses = [x1, x2]
    output_object = {"responses": []}
    for x in responses:
        json_object = x.json()
        output_object["responses"].append(json_object)
    json_str = json.dumps(output_object, indent=4)
    # Writing to weather_data.json
    with open("/tmp/weather_data.json", "w") as outfile:
        outfile.write(json_str)

def _download_data():
    with open('/tmp/weather_data.json') as f:
        d = json.load(f)
        responses = d["responses"]
        temps_K = [round(r["main"]["temp"] - 273.15, 2) for r in responses]
        names = [r["name"] for r in responses]
        df = pd.DataFrame({"names": names, "temps_K": temps_K})
        return df

def _process_data(ti):
    df = ti.xcom_pull(task_ids="download_data")
    df["temps_C"] = round(temps["temps_K"] - 273.15, 2)
    df.to_csv('/tmp/processed_weather_data.csv')
    return df

def _save_data(ti):
    df = ti.xcom_pull(task_ids="process_data")
    df.to_parquet('/tmp/weather.parquet')

with DAG("weather_data_pipeline_dag",
        schedule_interval="@once",
         start_date=datetime(2024,7,14)) as dag:
    taskPython0 = PythonOperator(
        task_id = "read_api_data",
        python_callable = _read_api_data
    )
    taskPython1 = PythonOperator(
        task_id = "download_data",
        python_callable = _download_data
    )
    taskPython2 = PythonOperator(
        task_id = "process_data",
        python_callable = _process_data
    )
    taskPython3 = PythonOperator(
        task_id = "save_data",
        python_callable = _save_data
    )
    taskPython0 >> taskPython1 >> taskPython2 >> taskPython3

But my dag failed. It read_api_data task failed. . How to solve that? where i can read LOG traceback of my DAG? it seems that airflow does not give details.

1

Did you read the error message you got?

Please install package apache-airflow instead of airflow

I think you should try that – pip install apache-airflow or to be very explicit about the Python version to use, python3 -m pip install apache-airflow – and try again.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật