当我执行CentOS中下面的函数,我得到的错误
def install_requests_lib():
try:
import requests
return
except ImportError, e:
print "module does not exist, installing..."
if(platform.system().lower()=='darwin'):
print "install requests before proceeding, run **sudo pip install requests**"
sys.exit(2)
elif(platform.system().lower()=='linux'):
print "installing"
p=Popen(["yum","-y","install","python-requests"], stdout=PIPE, shell=True)
p.communicate()
print p.returncode
错误:
module does not exist, installing...
installing
You need to give some command
1
我无法弄清楚什么是错的。
我stdin=PIPE
参数执行,我仍然得到同样的错误。
在您的ARG列表中的参数"yum"
后,如果你给的说法shell=True
没有被执行。取出shell=True
说法,它应该工作。
另外,您也可以在完整的命令行提供一个字符串,并保持shell=True
参数:
p=Popen("yum install -y python-requests", stdout=PIPE, shell=True)
但它一般不提倡这样做,for many reasons。
您正在尝试执行yum -y install
,当你的意思是yum install -y
。