Scrapy "ImportError" when 运行 inside bash script

Scrapy "ImportError" when running inside bash script

我有一个 Python 脚本 (blah.py),其中第一行是:

import scrapy

当我写 "python blah.py" 时它工作正常。

我有一个 .sh 脚本:

#!/bin/bash
python blah.py

当我使用 "sh blah.sh" 执行 .sh 脚本时,出现错误:

ImportError: No module named scrapy

我不明白为什么。我想从 .sh 文件中执行它,因为我在 Python 脚本之后执行了一些其他命令。

看起来你可能 运行 都在不同的环境中。

在 运行 python blah.py 时检查终端 which python 您使用的是哪个 python 版本,对于 bash 脚本也是如此,在python blah.py 行类型 which python

确保两条路径相同才能正常工作