Search code examples
pythondockervisual-studio-codeairflowimporterror

VScode shows import error , can't import DAG


I am trying to write script for DAG. I have run docker-airflow and is running well up on browser through localhost. But, whenever i try to open a dag file in vscode, it shows the import error.

I have installed and setup airflow using docker and activated docker using celery executor.

Docker Container for airflow is running.

from airflow import DAG
from airflow.operators.bash_operator import BashOperator

https://i.sstatic.net/K5zlC.png


Solution

  • Change the VS Code settings so you can run with your Docker virtual environment:

    Set python.pythonPath": "path_to_your_docker_virtual_environment\python.exe" at the JSON settings file and save it.

    After you can configure you VS Code to run within your docker virtual environment. Install the package with pip install apache-airflow and it will run.