gpt4 book ai didi

python - 找不到文件错误 : [Errno 2] No such file or directory: 'hdfs' : 'hdfs' using subprocess popen in crontab

转载 作者:行者123 更新时间:2023-12-05 03:45:06 26 4
gpt4 key购买 nike

我在 python3 中使用 subprocess.popen 在 hdfs 中放置文件或创建目录。它在 Linux shell 上使用 python3 准确运行。但是当我使用 crontab 运行代码时,我的日志文件出现“FileNotFoundError: [Errno 2] No such file or directory: 'hdfs': 'hdfs'”错误。

 make_dir = subprocess.Popen(['hdfs','dfs','-mkdir' , '-p' , hdfs_path])

最佳答案

当我的脚本在同一台机器上由 Airflow 执行时,我遇到了类似的问题,Airflow 没有加载我的环境变量。我不得不在代码中手动设置环境变量。你可以在代码中找到如何做到这一点 here .只需更新 PATH 以包含 Hadoop 二进制文件路径。还建议您可以在 cron 作业脚本中加载环境变量。喜欢:

#!/bin/bash
source $HOME/.bash_profile
some_other_cmd

more details

关于python - 找不到文件错误 : [Errno 2] No such file or directory: 'hdfs' : 'hdfs' using subprocess popen in crontab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66097700/

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