python脚本在启动时从终端执行时无法找到软件包,我在做什么错? [raspbian]
抱歉,如果这是显而易见的或多余的,我一直在此网站上寻找解决此问题的答案,但是我找不到任何可以解决
我要实现的目标的东西,就是当我的Raspberry Pi时执行Python脚本打开(桌面加载后),
我一直在尝试通过在/home/pi/.bashrc
的末尾添加这些行来做到这
echo Running at boot
sudo /usr/bin/python3.7m /home/pi/Desktop/Program/NameOfTheProgram.py
一点。标题是,当我打开终端时执行脚本,因此在启动时,python似乎无法找到包裹
from SSIM_PIL import compare_ssim as ssim #Import ssim from ssim package
ModuleNotFoundError: No module named 'SSIM_PIL'
使用从终端执行脚本时不会出现此问题
/usr/bin/python3.7m /home/pi/Desktop/Program/NameOfTheProgram.py
时,当我通过在这种情况下 该程序是按预期执行的,所以我唯一的猜测是我使用的python版本不应该是问题,因为我100%确定它是相同的,而且显然应该工作,但是我可能会误解
我也试图将相同的代码行放入/etc/rc.local
中,但我毫无用处,
我缺少某些东西吗?先感谢您
sorry in case this is obvious or redundant, I've been looking around on this site for an answer to this problem but I couldn't find anything that would fix it
What I am trying to achieve is executing a Python script when my raspberry pi turns on (after the desktop loads in)
I've been trying to do so by adding these lines at the end of /home/pi/.bashrc
echo Running at boot
sudo /usr/bin/python3.7m /home/pi/Desktop/Program/NameOfTheProgram.py
The problem, as you might've guessed from the title, is that when the script is executed as I open the terminal, and consequently at bootup, python doesn't appear to be capable of finding a package
from SSIM_PIL import compare_ssim as ssim #Import ssim from ssim package
ModuleNotFoundError: No module named 'SSIM_PIL'
This problem does not arise when I execute the script from the terminal by using
/usr/bin/python3.7m /home/pi/Desktop/Program/NameOfTheProgram.py
in which case the program is executed as intended, so my only guess is that this shouldn't be a problem with the python version I'm using, since I'm 100% sure it's the same one and it apparently should work, but I may be mistaken
I've also tried to put those same lines of code in /etc/rc.local
, but to no avail
Am I missing something? Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以在不同的时刻运行脚本:
cron
's@reboot
feature ) 。cron
和crontab
;读取手册页面!),涉及2和3;这在某种程度上取决于您使用的外壳。
阅读用户外壳的手册,并在文件部分中查看。
如果脚本不需要根特权,我喜欢使用
cron
,因为它支持运行命令作为非root用户。It is possible to run scripts at different moments:
cron
's@reboot
feature).cron
andcrontab
; read the manual pages!)Concerning 2 and 3; this depends somewhat on the shell you use.
Read the manual of the user's shell and look in the FILES section.
If a script does not require root privileges, I'm a fan of using
cron
, because it supports running commands as a non-root user.再次是我,就像Roberto指出的那样,从命令中删除
sudo
确实可以在打开终端窗口时执行程序确实有效,但不幸的现在需要做的是找到一种使用终端命令打开终端窗口的方法,并且该程序应正常工作,
这是可以承认的,但是只要程序可以
在启动i'上打开终端i'' VE在
lxSession
文件夹中编辑了autoStart
文件,通过向其添加@lxtryninal
,如这个答案我正在回答自己的问题,因为我不知道如何将评论标记为“答案”
It is me again, like Roberto pointed out removing
sudo
from the command did indeed work to execute the program when a terminal window is openedUnfortunately this didn't initiate the program at startup, but in theory all I need to do now is find a way to open a terminal window with a terminal command, and the program should be working correctly
This is admittedly a bit contrived, but it's good enough as long as the program works
To open the terminal on boot I've edited the
autostart
file in thelxsession
folder by adding@lxterminal
to it, as illustrated in this answerI'm answering to my own question as I don't know how to mark a comment as "answer", if that's even possible