python - 气流设置 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 论坛问题(虽然是不同的平台) Getting bash: airflow: command not found
一个 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
但它似乎没有击中我作为代理的提琴手(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
我得到了我拥有的 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时,它显示了与未释放连接相关的内容,我将进一步调查。
我的问题是:我必须为安装气流所做的所有解决方法,有没有更清洁的方法,我错过了什么?只是,这样我就不必一次又一次地做同样的事情。
PS:对Linux不是很精通。使用适用于 Windows 的 Ubuntu 18.04。
解决方案
终于通过以下方式解决了这个问题:
- 在 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
推荐阅读
- c# - 如何制作枚举值和整数的二维数组
- python - 将一个列表中的每个项目拆分为具有键值对的二维列表
- mysql - MySQL 使用引用连接表
- app-store - App Review 连接到托管应用服务
- javascript - 有没有办法将 CSV 列转换为层次关系?
- java - Java中套接字的OutputStreamWriter和InputStreamReader,我做错了什么?
- javascript - 在多个 JS 文件中使用 Jasmine,避免 db 竞争条件
- python - 如何使用 python 的 pandas 处理 excel 中的组合列?
- css - 将 h1 元素的宽度限制为其父元素
- java - OpenJDK 11 或 AdoptOpenJDK 是否与 Oracle JDK 一样稳定