问题

我在使用python的subprocess模块调用shell脚本时出现:spark-sql: command not found没有找到的问题。
解决
按照网上的思路是去/etc/profile配置文件里配置信息,然后我进入配置文件查看:vim /etc/profile

发现SPARK_HOME和PATH已经配置了,但是仍然出现该问题。所以猜想是配置文件没有生效的问题,所以在命令前加上:
source /etc/profile
这样的话问题就解决了:
subprocess.call("source /etc/profile; bash /home/tmp/train_data.sh", shell=True)
在使用Python的subprocess模块运行shell脚本遇到'command not found'错误,通常是因为环境变量未正确配置。尽管在/etc/profile中设置了SPARK_HOME和PATH,但配置未生效。通过在命令前添加`source /etc/profile`来使配置生效,解决了问题。最终的解决方案是使用`subprocess.call(source /etc/profile; bash /home/tmp/train_data.sh shell=True)`执行脚本。
3145

被折叠的 条评论
为什么被折叠?



