gpt4 book ai didi

windows - 在 WSL 上安装和运行 Airflow

转载 作者:行者123 更新时间:2023-12-04 18:42:24 29 4
gpt4 key购买 nike

我按照 this post 中的过程在 WSL(Windows 10)下的 Ubuntu 中安装了 Airflow .
但是在运行 airflow db init 时,我收到以下错误:

AttributeError: module 'wtforms.fields' has no attribute 'TextField'
完整的跟踪:
(airflow_env) sultani@Khalid:~/c/users/administrator/airflowhome$ airflow db init
DB: sqlite:///c/users/administrator/airflowhome/airflow.db
[2022-06-09 00:41:54,760] {db.py:1448} INFO - Creating tables
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
Traceback (most recent call last):
File "/home/sultani/.local/bin/airflow", line 8, in <module>
sys.exit(main())
File "/home/sultani/.local/lib/python3.8/site-packages/airflow/__main__.py", line 38, in main
args.func(args)
File "/home/sultani/.local/lib/python3.8/site-packages/airflow/cli/cli_parser.py", line 51, in command
return func(*args, **kwargs)
File "/home/sultani/.local/lib/python3.8/site-packages/airflow/cli/commands/db_command.py", line 35, in initdb
db.initdb()
File "/home/sultani/.local/lib/python3.8/site-packages/airflow/utils/session.py", line 71, in wrapper
return func(*args, session=session, **kwargs)
File "/home/sultani/.local/lib/python3.8/site-packages/airflow/utils/db.py", line 648, in initdb
upgradedb(session=session)
File "/home/sultani/.local/lib/python3.8/site-packages/airflow/utils/session.py", line 68, in wrapper
return func(*args, **kwargs)
File "/home/sultani/.local/lib/python3.8/site-packages/airflow/utils/db.py", line 1449, in upgradedb
command.upgrade(config, revision=to_revision or 'heads')
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/command.py", line 322, in upgrade
script.run_env()
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/script/base.py", line 569, in run_env
util.load_python_file(self.dir, "env.py")
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/util/pyfiles.py", line 94, in load_python_file
module = load_module_py(module_id, path)
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/util/pyfiles.py", line 110, in load_module_py
spec.loader.exec_module(module) # type: ignore
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/sultani/.local/lib/python3.8/site-packages/airflow/migrations/env.py", line 107, in <module>
run_migrations_online()
File "/home/sultani/.local/lib/python3.8/site-packages/airflow/migrations/env.py", line 101, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/runtime/environment.py", line 853, in run_migrations
self.get_context().run_migrations(**kw)
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/runtime/migration.py", line 611, in run_migrations
for step in self._migrations_fn(heads, self):
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/command.py", line 311, in upgrade
return script._upgrade_revs(revision, rev)
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/script/base.py", line 443, in _upgrade_revs
for script in reversed(list(revs))
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/script/revision.py", line 799, in iterate_revisions
revisions, heads = fn(
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/script/revision.py", line 1426, in _collect_upgrade_revisions
for rev in self._parse_upgrade_target(
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/script/revision.py", line 1218, in _parse_upgrade_target
return self.get_revisions(target)
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/script/revision.py", line 529, in get_revisions
resolved_id, branch_label = self._resolve_revision_number(
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/script/revision.py", line 753, in _resolve_revision_number
self._revision_map
File "/home/sultani/.local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 1095, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/script/revision.py", line 191, in _revision_map
for revision in self._generator():
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/script/base.py", line 140, in _load_revisions
script = Script._from_filename(self, vers, file_)
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/script/base.py", line 1013, in _from_filename
module = util.load_python_file(dir_, filename)
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/util/pyfiles.py", line 94, in load_python_file
module = load_module_py(module_id, path)
File "/home/sultani/.local/lib/python3.8/site-packages/alembic/util/pyfiles.py", line 110, in load_module_py
spec.loader.exec_module(module) # type: ignore
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/sultani/.local/lib/python3.8/site-packages/airflow/migrations/versions/0073_2_0_0_prefix_dag_permissions.py", line 27, in <module>
from flask_appbuilder import SQLA
File "/home/sultani/.local/lib/python3.8/site-packages/flask_appbuilder/__init__.py", line 6, in <module>
from .base import AppBuilder # noqa: F401
File "/home/sultani/.local/lib/python3.8/site-packages/flask_appbuilder/base.py", line 8, in <module>
from .api.manager import OpenApiManager
File "/home/sultani/.local/lib/python3.8/site-packages/flask_appbuilder/api/manager.py", line 8, in <module>
from flask_appbuilder.baseviews import BaseView
File "/home/sultani/.local/lib/python3.8/site-packages/flask_appbuilder/baseviews.py", line 21, in <module>
from .forms import GeneralModelConverter
File "/home/sultani/.local/lib/python3.8/site-packages/flask_appbuilder/forms.py", line 25, in <module>
from .models.mongoengine.fields import MongoFileField, MongoImageField
File "/home/sultani/.local/lib/python3.8/site-packages/flask_appbuilder/models/mongoengine/fields.py", line 4, in <module>
from ...upload import BS3FileUploadFieldWidget, BS3ImageUploadFieldWidget
File "/home/sultani/.local/lib/python3.8/site-packages/flask_appbuilder/upload.py", line 106, in <module>
class FileUploadField(fields.TextField):
AttributeError: module 'wtforms.fields' has no attribute 'TextField'

最佳答案

不幸的是,您链接的博客文章存在很多问题:

  • 它至少有两个错误。首先,缺少 /在前面的AIRFLOW_HOME多变的。此外,该博客建议更改您的 /mnt/c简单地说/c , 但随后继续使用 /mnt/cAIRFLOW_HOME这是行不通的。
  • 坏建议——一般来说,你不应该将 Windows 驱动器(例如 /mnt/c )用于 WSL2 项目。有性能问题和权限问题需要处理。
  • 不必要的步骤——绝对没有理由将您的 WSL 自动挂载目录更改为 /即使您使用了将 Airflow 安装到 Windows 驱动器的错误建议。我建议编辑您的 WSL 配置文件以更改此设置,除非您出于其他原因需要它。删除root = /来自 /etc/wsl.conf 的行.
  • 不必要的软件包和存储库——没有理由添加 Universe,因为它已经存在(并且一直存在)在 WSL Ubuntu 中。没有理由安装software-properties-commonpython-setuptools或者——它们不是必需的。
  • 最糟糕的是,它只是过时和/或与 official doc 冲突。 .这是您安装的最大问题——在实际安装过程中您会看到一个错误,即存在不兼容的软件包版本。

  • 因此,让我推荐以下组合:
  • Python 最佳实践——该博客在某种程度上确实做到了这一点,使用虚拟环境来避免污染通用 Python 系统包。
  • WSL2 最佳实践——你真的可以按照上面链接的官方文档进行操作。博客文章只是一个糟糕的方法。
  • 官方文档。

  • 如果您没有将它用于其他任何事情,您可能只想删除您的 Ubuntu WSL2 安装并重新开始。我从一个干净的 Ubuntu 20.04 WSL2 安装开始来演示这一点:
    sudo apt update && sudo apt upgrade -y
    sudo apt install python3-pip python3-venv
    mkdir -p ~/airflow/airflowhome
    python3 -m venv ~/airflow/airflowenv
    source ~/airflow/airflowenv/bin/activate
    # Your prompt will change to "airflowenv"
    pip3 install wheel # Not found in venv by default, but recommended for packages
    此时,我们直接从 Apache Airflow docs 开始工作。除了较小的目录更改之外没有实质性更改:
    export AIRFLOW_HOME=~/airflow/airflowhome
    AIRFLOW_VERSION=2.3.2
    PYTHON_VERSION="$(python --version | cut -d " " -f 2 | cut -d "." -f 1-2)"
    CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"
    pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"
    仔细观察输出。您应该在那里看不到任何错误——之前使用博客说明的尝试显示了红色文本错误,提前表明了问题。
    现在:
    airflow standalone
    这将启动服务器。正如医生所说,密切注意屏幕上的最后几行。它将列出您的管理员用户名和密码。您可以使用它通过 Windows 网络浏览器登录 http://localhost:8080。 .
    您仍然可以添加 export AIRFLOW_HOME向您的 ~/.bashrc 声明,但是既然你每次都需要激活venv,那么最好就这样做。所以下次运行它,你会:
    source ~/airflow/airflowenv/bin/activate
    export AIRFLOW_HOME=~/airflow/airflowhome
    airflow standalone
    注意:任何时候你做 source ~/airflow/airflowenv/bin/activate ,您将处于 Python 虚拟环境中。要返回到此时的默认 Python 系统环境,只需运行 deactivate .
    我自己不是 Airflow 用户,因此我无法为您提供更多帮助。但这些是至少在 WSL2 Ubuntu 上对我有用的步骤,以使其启动并运行。

    关于windows - 在 WSL 上安装和运行 Airflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72551825/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com