Python ImportError:shell文件中没有名为twitter的模块

Python ImportError:shell文件中没有名为twitter的模块,python,shell,twitter,Python,Shell,Twitter,所以我安装了twitter 轻松安装twitter my_file.py import twitter ...... ...... 当我直接在终端上运行python文件时,它工作得很好 >python my_file.py 但是,当我将上述内容放入shell文件时 运行_script.sh python my_file.py 我使用 >sh run_script.sh 我犯了一个错误 ImportError: No module named 'twitter' 当我通过sh

所以我安装了twitter 轻松安装twitter

my_file.py

import twitter
......
......
当我直接在终端上运行python文件时,它工作得很好

>python my_file.py
但是,当我将上述内容放入shell文件时

运行_script.sh

python my_file.py
我使用

>sh run_script.sh
我犯了一个错误

ImportError: No module named 'twitter'

当我通过shell脚本尝试导入模块时,为什么它不能识别导入的模块安装后?

您需要在文件顶部给出一个sha-bang,如-

#!/usr/bin/env python
import twitter
Your code goes here ...
然后在终端运行这个命令,使这个文件可执行

$ chmod +x my_file.py
并将其添加到bash脚本中:-

./my_file.py

另外,请确保您已全局安装了模块,而不是将其安装在virtualenv

/my_file.py。。。。。当你说在bash脚本中添加这个时,你到底是什么意思?您是说将其添加到run_script.sh文件中?这条线的目的是什么