初始化db时,importerror:无法导入名称hiveoperator

pxq42qpu  于 2021-06-28  发布在  Hive
关注(0)|答案(3)|浏览(466)

我最近安装了 airflow 我的工作流程。在创建项目时,我执行了以下命令:

airflow initdb

返回以下错误:

[2016-08-15 11:17:00,314] {__init__.py:36} INFO - Using executor SequentialExecutor
DB: sqlite:////Users/mikhilraj/airflow/airflow.db
[2016-08-15 11:17:01,319] {db.py:222} INFO - Creating tables
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [airflow.models.DagBag] Failed to import: /usr/local/lib/python2.7/site-packages/airflow/example_dags/example_twitter_dag.py
Traceback (most recent call last):
    File "/usr/local/lib/python2.7/site-packages/airflow/models.py", line 247, in process_file
       m = imp.load_source(mod_name, file path)
    File "/usr/local/lib/python2.7/site-packages/airflow/example_dags/example_twitter_dag.py", line 26, in <module>
       from airflow.operators import BashOperator, HiveOperator, PythonOperator
ImportError: cannot import name HiveOperator
Done.

我在网上查了一些类似的问题,建议我安装 airflow[hive] , pyhs2 但似乎不起作用。

gj3fmq9x

gj3fmq9x1#

检查是否在dag文件中导入了配置单元操作符?如果没有,您可以执行以下操作: from airflow.operators.hive_operator import HiveOperator

vatpfxk5

vatpfxk52#

你在用那个吗 HiveOperator ? 似乎您得到的错误是由于示例DAG中的一个。在生产中,你可能应该 load_examplesFalse 安装 airflow[hive] 只有在使用hiveoperator时。
话说回来,不知道为什么 airflow[hive] 对你来说还不够。您可以尝试安装 airflow[hive,hdfs,jdbc] 但是气流[Hive]应该足以摆脱 HiveOperator 导入错误。你能补充一下你还有什么错误吗?

cnwbcb6i

cnwbcb6i3#

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/airflow/models.py", line 247, in process_file
    m = imp.load_source(mod_name, filepath)
  File "/usr/local/lib/python2.7/dist-packages/airflow/example_dags/example_twitter_dag.py", line 26, in <module>
    from airflow.operators import BashOperator, HiveOperator, PythonOperator
ImportError: cannot import name HiveOperator

如果仍要继续安装示例数据。。。对于ubuntu 14.04,请在最新的Python2.7中使用此方法(在do处测试)
1.apt-get更新
2.apt-get安装python pip python dev build essential
3.pip安装--升级pip
3a.哪个pip#/usr/local/bin/pip
3b.pip-v#pip 9.0.1来自/usr/local/lib/python2.7/dist-packages(python2.7)
4.pip安装--升级virtualenv
(任务5是可选的)
5.apt-get安装sqlite3 libsqlite3 dev
https://askubuntu.com/questions/683601/how-to-upgrade-python-setuptools-12-2-on-ubuntu-15-04
6.apt-get删除python设置工具
7.pip安装-u pip setuptools
8.导出气流\u home=~/气流
9.1安装气流
10.pip安装气流[Hive]
11.1数据库
您将在下面得到此响应

[2017-02-01 12:04:28,289] {__init__.py:36} INFO - Using executor SequentialExecutor
[2017-02-01 12:04:28,350] {driver.py:120} INFO - Generating grammar tables from /usr/lib/python2.7/lib2to3/Grammar.txt
[2017-02-01 12:04:28,376] {driver.py:120} INFO - Generating grammar tables from /usr/lib/python2.7/lib2to3/PatternGrammar.txt
DB: sqlite:////root/airflow/airflow.db
[2017-02-01 12:04:28,522] {db.py:222} INFO - Creating tables
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Done.

注:如适用,请使用必要的sudo命令

相关问题