1
我已经在我的Ubuntu 15.10上从源手动构建了python3.5.2。构建过程进行得很顺利,但现在当我执行下面的脚本来自Python的子进程:子进程没有“运行”属性
import subprocess
print(subprocess.run(["ls"]))
我收到下面的输出:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'run'
当我在Windows(其中我已经安装了通过安装python3.5.2)上运行相同的脚本我收到预期的输出:
CompletedProcess(args='ls', returncode=0)
在我的ubuntu机器上,subprocess.py存在并且它具有定义的“运行”功能。 我预计python3.5.2可以在libs文件夹中查找subprocess.py for 2.7(在Ubuntu上预装),但事实并非如此。
我的安装有什么问题?
尝试在你的脚本打印Python版本。 'import sys; print sys.version'。 –
回溯消息表明您仍在Python 3中运行Python 2(至少在Python 3.5.1中),回溯将如下所示:'AttributeError:module'subprocess'没有属性'run'。 –
@AshwiniChaudhary感谢您的评论。这真的很奇怪,因为它在Ubuntu上输出3.4.3,在Windows上输出3.5.2。 –