![运行 bash shell 脚本时出现 ModuleNotFoundError,但在使用 python 在终端中运行时工作正常](https://linux22.com/image/201544/%E8%BF%90%E8%A1%8C%20bash%20shell%20%E8%84%9A%E6%9C%AC%E6%97%B6%E5%87%BA%E7%8E%B0%20ModuleNotFoundError%EF%BC%8C%E4%BD%86%E5%9C%A8%E4%BD%BF%E7%94%A8%20python%20%E5%9C%A8%E7%BB%88%E7%AB%AF%E4%B8%AD%E8%BF%90%E8%A1%8C%E6%97%B6%E5%B7%A5%E4%BD%9C%E6%AD%A3%E5%B8%B8.png)
所以我试图在 1 个脚本中一起运行 3 个独立的不和谐机器人。
start.sh 脚本如下所示;
node spamprevention/index.js > logs/spamprevention.log 2>&1 &
node reportbot/index.js > logs/reportbot.log 2>&1 &
python main.py
while :; do
sleep 5
done
在该目录中,&文件夹以及和文件所在pi@tradehubrpi:~/discordbots/trade-hub-secret-agent
的位置。我在终端中输入来启动这个脚本。spamprevention
reportbot
start.sh
main.py
bash start.sh
这是日志;
pi@tradehubrpi:~/discordbots/trade-hub-secret-agent $ bash start.sh
start.sh: line 1: logs/spamprevention.log: Permission denied
start.sh: line 2: logs/reportbot.log: Permission denied
Traceback (most recent call last):
File "main.py", line 13, in <module>
from discord import * # import library
File "/home/pi/discordbots/trade-hub-secret-agent/discord/__init__.py", line 21, in <module>
from typing import NamedTuple, Literal
ImportError: cannot import name 'Literal' from 'typing' (/usr/lib/python3.7/typing.py)
^C
pi@tradehubrpi:~/discordbots/trade-hub-secret-agent $ sudo bash start.sh
Traceback (most recent call last):
File "main.py", line 10, in <module>
import aiohttp
ModuleNotFoundError: No module named 'aiohttp'
2 个 javascript 机器人运行良好,但对于 python 机器人,我得到了ModuleNotFoundError
.但是当我python main.py
在终端运行时它工作正常。
正如您现在所知,我不是开发人员。有一个简单的解决办法吗? (在 Raspberry Pi 4 上运行这些)
编辑;没有运行日志python main.py
,这意味着它运行正确,日志将显示是否存在错误或不和谐的某种类型的操作。
运行时sudo python main.py
返回此;
pi@tradehubrpi:~/discordbots/trade-hub-secret-agent $ sudo python main.py
Traceback (most recent call last):
File "main.py", line 13, in <module>
from discord import * # import library
File "/home/pi/discordbots/trade-hub-secret-agent/discord/__init__.py", line 21, in <module>
from typing import NamedTuple, Literal
ImportError: cannot import name 'Literal' from 'typing' (/usr/lib/python3.7/typing.py)