如何解决通过systemd服务调用脚本时导入rospy时出现导入错误
我正在尝试运行使用rospy的python脚本。通常,通过命令行python3 npnt_main.py
调用此脚本时,它运行良好。
但是当通过systemd服务运行时,出现以下错误:
ModuleNotFoundError: No module named 'rospy'
systemd服务如下:
[Unit]
Description=Npnt Compliance service
[Service]
WorkingDirectory=/srv/maverick/code/maverick/custom-modules/NpntCompliance/catkin_ws/src/npnt_test/
ExecStart=/bin/sh /srv/maverick/code/maverick/custom-modules/NpntCompliance/catkin_ws/src/npnt_test/run/run_npnt.sh &
User=root
Restart=on-failure
RestartSec=3
[Install]
WantedBy=multi-user.target
脚本run_npnt.sh如下:
#!/usr/bin/env bash
# To start npnt_main and handle crashes
BASE="/srv/maverick/code/maverick/custom-modules/NpntCompliance/catkin_ws/src/npnt_test"
echo "Starting npnt"
LOGFILE="$BASE/log/npnt_syslogs.log"
[ -e $LOGFILE ] && rm $LOGFILE > /dev/null 2>&1
echo "Old Logfile: $LOGFILE deleted"
echo "Running npnt"
python3 $BASE/scripts/npnt_main.py > $LOGFILE
ret=$?
if [ $ret -ne 0 ]; then
echo "npnt_main crashed. Restarting"
fi
如何在不出现ImportError的情况下通过systemd服务运行它?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。