Airflow安装后找不到主模块

huangapple go评论52阅读模式
英文:

Airflow can't find main module after install

问题

I just installed Python 3.10.11 on Suse SLES-15.4. Python runs as expected:

~> python3 -c "import os, sys; print(os.path.dirname(sys.executable))"
/usr/bin
~> pip3 --version
pip 22.0.4 from /usr/lib/python3.10/site-packages/pip (python 3.10)

As I am not a fan of having an aplication installed in my personal home folder, so I defined the AIRFLOW_HOME to a directory which I created:

export AIRFLOW_HOME=/usr/lib/airflow

Then, as written in the quick start guide, I defined the following variables:

AIRFLOW_VERSION=2.6.1
PYTHON_VERSION="$(python3 --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

and then proceeded with install:

pip3 install -t $AIRFLOW_HOME "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"

I tried to configure the /etc/profile.d/python.sh to guess what could prevent Airflow from starting:

# add python startup script for interactive sessions
export PYTHONSTARTUP=/etc/pythonstart
export LC_ALL="fr_CH.UTF-8"
export AIRFLOW_HOME=/usr/lib/airflow
export PATH=/usr/lib:/usr/lib/airflow:/usr/lib/airflow/bin:$PATH
export LD_LIBRARY_PATH=/usr/lib/airflow:/usr/lib/airflow/bin/airflow:/usr/lib/python3.10:/usr/lib/python3.10/site-packages:$LD_LIBRARY_PATH

But still, when I try to run Airflow at first, I receive an error message:

~> airflow standalone
Traceback (most recent call last):
  File "/usr/lib/airflow/bin/airflow", line 5, in <module>
    from airflow.__main__ import main
ModuleNotFoundError: No module named 'airflow'

Do you have any suggestion to solve this?

英文:

I just installed Python 3.10.11 on Suse SLES-15.4.
Python runs as expected:

~&gt; python3 -c &quot;import os, sys; print(os.path.dirname(sys.executable))&quot;
/usr/bin
~&gt; pip3 --version
pip 22.0.4 from /usr/lib/python3.10/site-packages/pip (python 3.10)

As I am not a fan of having an aplication installed in my personal home folder, so I defined the AIRFLOW_HOME to a directory which I created :

export AIRFLOW_HOME=/usr/lib/airflow

Then, as written in the quick start guide, I defined the following variables:

AIRFLOW_VERSION=2.6.1
PYTHON_VERSION=&quot;$(python3 --version | cut -d &quot; &quot; -f 2 | cut -d &quot;.&quot; -f 1-2)&quot;
CONSTRAINT_URL=https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt

and then proceeded with install:

pip3 install -t $AIRFLOW_HOME &quot;apache-airflow==${AIRFLOW_VERSION}&quot; --constraint &quot;${CONSTRAINT_URL}&quot;

I tried to configure the /etc/profile.d/python.sh to guess what could prevent Airflow from starting:

# add python startup script for interactive sessions
export PYTHONSTARTUP=/etc/pythonstart
export LC_ALL=&quot;fr_CH.UTF-8&quot;
export AIRFLOW_HOME=/usr/lib/airflow
export PATH=/usr/lib:/usr/lib/airflow:/usr/lib/airflow/bin:$PATH
export LD_LIBRARY_PATH=/usr/lib/airflow:/usr/lib/airflow/bin/airflow:/usr/lib/python3.10:/usr/lib/python3.10/site-packages:$LD_LIBRARY_PATH

But still, when I try to run Airflow at first, I receive an error message:

~&gt; airflow standalone
Traceback (most recent call last):
  File &quot;/usr/lib/airflow/bin/airflow&quot;, line 5, in &lt;module&gt;
    from airflow.__main__ import main
ModuleNotFoundError: No module named &#39;airflow&#39;

Do you have any suggestion to solve this?

答案1

得分: 0

pip包没有安装在可以读取的位置。
要修复它,您可以在文件**/etc/profile.d/python.sh**的其余导出中添加以下内容:

# ...
export PYTHONPATH=$PYTHONPATH:$AIRFLOW_HOME

或者您可以尝试在不使用标志-t $AIRFLOW_HOME的情况下安装airflow,因为它将安装在默认的PYTHONPATH中,与其他pip包一起分配。

英文:

The pip package is not getting installed in a place where it can be read.
To fix it you can add to the rest of exports in the file /etc/profile.d/python.sh:

# ...
export PYTHONPATH=$PYTHONPATH:$AIRFLOW_HOME

Or you can try to install airflow without the flag: -t $AIRFLOW_HOME since it will be installed in the default PYTHONPATH assigned with the rest of pip packages.

huangapple
  • 本文由 发表于 2023年6月12日 21:34:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457198.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定