skip to Main Content

I installed Airflow in Ubuntu under WSL (Windows 10) by following the process in this post.

But when running airflow db init, I get the following error:

AttributeError: module 'wtforms.fields' has no attribute 'TextField'

Complete trace:

(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'

2

Answers


  1. Chosen as BEST ANSWER

    thanks for reply , there were several issue in the blog provided, and i managed to run airflow locally .

    1. / was missing before C the path had to be changed to AIRFLOW_HOME=/c/users/YOURNAME/airflowhome .
    2. i had to install airflow from https://pypi.org/project/apache-airflow/ the rest of steps were fine.

    since i am new to airflow i need to fix some other issue now in pycharm it gives missing dependencies when i create dag file inside dag folder.


  2. There are unfortunately quite a few problems with the blog post you linked:

    • It has at least two errors. First, a missing / at the front of the front of the AIRFLOW_HOME variable. Also, the blog suggests changing your /mnt/c to simply /c, but then goes on to use the /mnt/c in the AIRFLOW_HOME which wouldn’t work.

    • Bad advice — In general, you should not use Windows drives (e.g. /mnt/c) for WSL2 projects. There are both performance issues and permissions issues to deal with.

    • Unnecessary steps — There’s absolutely no reason to change your WSL automount directory to / even if you were using the bad advice of installing Airflow to your Windows drive. I recommend editing your WSL configuration file to change this unless you want it there for other reasons. Delete the root = / line from /etc/wsl.conf.

    • Unnecessary packages and repos — There’s no reason to add Universe, since it’s already there (and always has been) in WSL Ubuntu. There’s no reason to install software-properties-common or python-setuptools either — They aren’t needed.

    • And worst of all, it’s just plain outdated and/or conflicts the official doc. That’s the biggest problem with your installation — You’ll have seen an error during the actual install that there are incompatible package versions.

    So let me recommend a combination of:

    • Python best practices — The blog actually does this to some degree, using a virtual environment to avoid polluting the general Python system packages.
    • WSL2 best practices — For which you really can just follow the official doc linked above. The blog post is simply a bad way to do it.
    • The official doc.

    You might want to just erase your Ubuntu WSL2 installation and start over at this point if you weren’t using it for anything else. I’m starting from a clean Ubuntu 20.04 WSL2 installation to demonstrate this:

    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
    

    At this point, we start working directly from the Apache Airflow docs with no substantial changes other than a minor directory change:

    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}"
    

    Watch the output closely. You should see no errors there — The previous attempt using the blog instructions showed red-text-errors that indicated the problem in advance.

    Now:

    airflow standalone
    

    That starts the server. As the doc says, pay close attention to the last few lines on the screen. It will have your admin username and password listed. You can use that to login via your Windows web browser at http://localhost:8080.

    You could still add the export AIRFLOW_HOME statement to your ~/.bashrc, but since you need to active the venv each time anyway, probably best just to do it then. So to run it next time, you would:

    source ~/airflow/airflowenv/bin/activate
    export AIRFLOW_HOME=~/airflow/airflowhome
    airflow standalone
    

    Note: Any time you do source ~/airflow/airflowenv/bin/activate, you’ll be in the Python virtual environment. To return to the default Python system environment at that point, simply run deactivate.

    I’m not an Airflow user myself, so I can’t help you much further than that. But those are the steps that worked for me on WSL2 Ubuntu for getting it up-and-running, at least.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search