【问题标题】:Sudoer does not use the same environnement for python3sudo 不使用与 python3 相同的环境
【发布时间】:2021-01-02 05:27:41
【问题描述】:

我有一个 python script1,我将它用作我导入到我的主脚本的库。 在使用它之前,我检查了它是否工作正常,我注意到当我使用“sudo”运行这个 script1 时,它找不到他使用的库之一。

sudo python3 -W ignore detector.py -d datasets -c MLP predict

稍微搜索了一下,发现“sudo”和我的用户账号使用的环境不一样,需要加上参数“-E”,效果很好。

sudo -E python3 -W ignore detector.py -d datasets -c MLP predict

当我在没有“sudo”的情况下运行 script1 时,它也能正常工作

python3 -W ignore detector.py -d datasets -c MLP predict

然后我将我的 script1 导入我的主脚本“import script1”并从 script1 调用其中一个函数,但从 script1 得到相同的错误。

问题是我的主脚本是由 systemctl 管理的,带有 root 用户的服务,我不能在 ExecStart 中使用“-E”:

[Unit]

Description= Uplink manager with IA supervison of LORAWAN data
Wants=network-online.target
After=network-online.target  
[Service]
ExecStart=  /usr/bin/python3 -u/opt/flask_server/uplink_server/uplink_manager.py
Restart=on-failure   
[Install]
WantedBy=multi-user.target
Alias=uplink_manager.service

你能帮帮我吗?谢谢。

【问题讨论】:

    标签: linux python-import python-3.7 sudo sudoers


    【解决方案1】:

    丢失的库实际上存在于根环境中,但库的版本不对。

    【讨论】:

      猜你喜欢
      • 2011-06-25
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 2019-07-10
      相关资源
      最近更新 更多