AirFlow 设置 WSL
AirFlow setup WSL
我正在尝试在 WSL 中设置 AirFlow,运行遇到问题。我已经浏览了文章和 SO 但无法解决这个问题。
我正在按照 Airlfow 教程 https://airflow.apache.org/docs/stable/tutorial.html 进行设置。
我能够 运行 运行 上面教程中的最终脚本而没有错误。基本上这段代码
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
default_args = {
'owner': 'Airflow',
'depends_on_past': False,
'start_date': datetime(2015, 6, 1),
'email': ['airflow@example.com'],
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
# 'queue': 'bash_queue',
# 'pool': 'backfill',
# 'priority_weight': 10,
# 'end_date': datetime(2016, 1, 1),
}
dag = DAG(
'tutorial', default_args=default_args, schedule_interval=timedelta(days=1))
# t1, t2 and t3 are examples of tasks created by instantiating operators
t1 = BashOperator(
task_id='print_date',
bash_command='date',
dag=dag)
t2 = BashOperator(
task_id='sleep',
bash_command='sleep 5',
retries=3,
dag=dag)
templated_command = """
{% for i in range(5) %}
echo "{{ ds }}"
echo "{{ macros.ds_add(ds, 7)}}"
echo "{{ params.my_param }}"
{% endfor %}
"""
t3 = BashOperator(
task_id='templated',
bash_command=templated_command,
params={'my_param': 'Parameter I passed in'},
dag=dag)
t2.set_upstream(t1)
t3.set_upstream(t1)
然后我可以使用
无误地执行它
python ~/airflow/dags/FirstTest.py
然而,当我尝试 运行 命令时
airflow list_dags
我收到一条错误消息
airflow: command not found
我能够执行 pip install apache-airflow,因此原始脚本可以 运行。
但是,根据这个 SO 论坛问题(虽然是不同的平台)
a SUDO pip install pip 修复了它,但在我的情况下它给了我一个错误说
'/home/sum/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled
然后我使用了-H标志意思
sudo -H pip3 install apache-airflow
但它似乎没有命中我作为代理的 fiddler (127.0.0.1:8888),因此出现连接被拒绝的错误
因此我修改它以使用
显式包含代理
sudo pip3 --proxy=http://127.0.0.1:8888 install apache-airflow
但后来我 运行 遇到了一个问题,所有问题都转到了 pypi 而不是我想要的 npm.sys.dom。
在我的 /etc/profile 文件中我有
export http_proxy=http://127.0.0.1:8888
export https_proxy=http://127.0.0.1:8888
export pip_index_url=http://npm.sys.dom:81/pypi/Python/simple
export pip_trusted_host=npm.sys.dom
但不知何故,VS 代码似乎无法识别它。
我尝试在 VS 代码中设置“.profile”文件,这是在我选择打开与我的主目录对应的文件夹后出现的,使用与上面相同的 4 行。
但 sudo pip install 仍然无法接收它。
我终于绕过了
sudo pip3 --proxy=http://127.0.0.1:8888 trusted-host npm.sys.dom index-url http://npm.sys.dom:81/pypi/Python/simple install apache-airflow
但是现在当我运行
airflow list_dags
我得到了我的错误,但在得到输出之前我也遇到了一堆错误
ERROR - Failed on pre-execution callback using <function default_action_log at 0x7fa84c2db510>
Traceback (most recent call last):
File "/home/sum/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1246, in _execute_context
cursor, statement, parameters, context
File "/home/sum/.local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 581, in do_execute
cursor.execute(statement, parameters)
sqlite3.OperationalError: no such table: log
......
(Background on this error at: http://sqlalche.me/e/e3q8)
当我查看 http://sqlalche.me/e/e3q8 时,它显示与未释放连接相关的内容,我将进一步调查。
我的问题是:安装 airflow 我必须做的所有变通办法,有没有更干净的方法,我错过了什么?只是,这样我就不用一次又一次地做同样的事情了。
P.S:不太精通Linux。 Ubuntu 18.04 用于 Windows.
终于解决了这个问题:
- 在 bashrc 文件中添加了 http 和 https 代理,这样我就不必每次在 VSCode 中使用 pip3 时都指定它。 Fiddler 是这里的代理。
echo 'export HTTP_PROXY="127.0.0.1:8888"' >> ~/.bashrc
echo 'export HTTPS_PROXY="127.0.0.1:8888"' >> ~/.bashrc
- 在 python 中创建虚拟环境并在虚拟环境中安装 apache-airflow
apt-get install python3-venv
#Please replace or choose your own path. The one below is a sample
python3 -m venv /home/usrname/airflow
source /home/usrname/airflow/bin/activate
#finally install airflow. Remember to install setuptools before. I also had other packages to install
pip install setuptools_git "pymssql<3.0" pyodbc
pip install apache-airflow
我正在尝试在 WSL 中设置 AirFlow,运行遇到问题。我已经浏览了文章和 SO 但无法解决这个问题。
我正在按照 Airlfow 教程 https://airflow.apache.org/docs/stable/tutorial.html 进行设置。 我能够 运行 运行 上面教程中的最终脚本而没有错误。基本上这段代码
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
default_args = {
'owner': 'Airflow',
'depends_on_past': False,
'start_date': datetime(2015, 6, 1),
'email': ['airflow@example.com'],
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
# 'queue': 'bash_queue',
# 'pool': 'backfill',
# 'priority_weight': 10,
# 'end_date': datetime(2016, 1, 1),
}
dag = DAG(
'tutorial', default_args=default_args, schedule_interval=timedelta(days=1))
# t1, t2 and t3 are examples of tasks created by instantiating operators
t1 = BashOperator(
task_id='print_date',
bash_command='date',
dag=dag)
t2 = BashOperator(
task_id='sleep',
bash_command='sleep 5',
retries=3,
dag=dag)
templated_command = """
{% for i in range(5) %}
echo "{{ ds }}"
echo "{{ macros.ds_add(ds, 7)}}"
echo "{{ params.my_param }}"
{% endfor %}
"""
t3 = BashOperator(
task_id='templated',
bash_command=templated_command,
params={'my_param': 'Parameter I passed in'},
dag=dag)
t2.set_upstream(t1)
t3.set_upstream(t1)
然后我可以使用
无误地执行它python ~/airflow/dags/FirstTest.py
然而,当我尝试 运行 命令时
airflow list_dags
我收到一条错误消息
airflow: command not found
我能够执行 pip install apache-airflow,因此原始脚本可以 运行。
但是,根据这个 SO 论坛问题(虽然是不同的平台)
a SUDO pip install pip 修复了它,但在我的情况下它给了我一个错误说
'/home/sum/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled
然后我使用了-H标志意思
sudo -H pip3 install apache-airflow
但它似乎没有命中我作为代理的 fiddler (127.0.0.1:8888),因此出现连接被拒绝的错误
因此我修改它以使用
显式包含代理sudo pip3 --proxy=http://127.0.0.1:8888 install apache-airflow
但后来我 运行 遇到了一个问题,所有问题都转到了 pypi 而不是我想要的 npm.sys.dom。
在我的 /etc/profile 文件中我有
export http_proxy=http://127.0.0.1:8888
export https_proxy=http://127.0.0.1:8888
export pip_index_url=http://npm.sys.dom:81/pypi/Python/simple
export pip_trusted_host=npm.sys.dom
但不知何故,VS 代码似乎无法识别它。
我尝试在 VS 代码中设置“.profile”文件,这是在我选择打开与我的主目录对应的文件夹后出现的,使用与上面相同的 4 行。
但 sudo pip install 仍然无法接收它。
我终于绕过了
sudo pip3 --proxy=http://127.0.0.1:8888 trusted-host npm.sys.dom index-url http://npm.sys.dom:81/pypi/Python/simple install apache-airflow
但是现在当我运行
airflow list_dags
我得到了我的错误,但在得到输出之前我也遇到了一堆错误
ERROR - Failed on pre-execution callback using <function default_action_log at 0x7fa84c2db510>
Traceback (most recent call last):
File "/home/sum/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1246, in _execute_context
cursor, statement, parameters, context
File "/home/sum/.local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 581, in do_execute
cursor.execute(statement, parameters)
sqlite3.OperationalError: no such table: log
......
(Background on this error at: http://sqlalche.me/e/e3q8)
当我查看 http://sqlalche.me/e/e3q8 时,它显示与未释放连接相关的内容,我将进一步调查。
我的问题是:安装 airflow 我必须做的所有变通办法,有没有更干净的方法,我错过了什么?只是,这样我就不用一次又一次地做同样的事情了。
P.S:不太精通Linux。 Ubuntu 18.04 用于 Windows.
终于解决了这个问题:
- 在 bashrc 文件中添加了 http 和 https 代理,这样我就不必每次在 VSCode 中使用 pip3 时都指定它。 Fiddler 是这里的代理。
echo 'export HTTP_PROXY="127.0.0.1:8888"' >> ~/.bashrc
echo 'export HTTPS_PROXY="127.0.0.1:8888"' >> ~/.bashrc
- 在 python 中创建虚拟环境并在虚拟环境中安装 apache-airflow
apt-get install python3-venv
#Please replace or choose your own path. The one below is a sample
python3 -m venv /home/usrname/airflow
source /home/usrname/airflow/bin/activate
#finally install airflow. Remember to install setuptools before. I also had other packages to install
pip install setuptools_git "pymssql<3.0" pyodbc
pip install apache-airflow