【发布时间】:2018-02-21 03:11:18
【问题描述】:
我的代码使用 subprocess.check_output 很好,我不得不重新安装 Ubuntu 16.04,然后它抱怨它现在找不到属性 check_output。
import subprocess
p = subprocess.check_output("here is a command", shell=True)
/usr/bin/python2.7 /home/username/subprocess.py
Traceback (most recent call last):
File "/home/username/subprocess.py", line 1, in <module>
import subprocess
File "/home/username/subprocess.py", line 4, in <module>
p = subprocess.check_output("here is a command", shell=True)
AttributeError: 'module' object has no attribute 'check_output'
请注意,我使用的是 Python2.7,根据这里的这篇文章应该可以解决这个问题,但它没有。
subprocess.check_output() module object has out attribute 'check_output'
什么给了?我试过 pip install subprocess 或 pip uninstall subprocess 但没有运气。如何将subprocess 更新到最新版本,使其具有check_output 属性?我不想使用Popen。
【问题讨论】:
-
你能告诉我们你是如何确定你正在使用 Python2.7 的吗?你能提供一些在交互式 shell 中运行相同步骤的输出吗?
标签: python python-2.7 subprocess