【发布时间】:2014-11-26 11:12:43
【问题描述】:
pip 在 pypi 网站上找不到这个模块,我也找不到。 请告诉我秘密,如何安装?
我需要该模块通过 subprocess.call 生成新的 shell 进程。我见过很多例子,人们使用import subprocess,但没有人展示它是如何安装的。
错误,我得到了(以防我失去理智并且不明白发生了什么):
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Alexander\Desktop\tests-runner>python run.py
Traceback (most recent call last):
File "run.py", line 165, in <module>
main()
File "run.py", line 27, in main
subprocess.call('py.test')
File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
【问题讨论】:
-
它是内置的,您不必安装它。你的 python 版本是多少?
-
subprocess模块是标准库的一部分,它不需要(实际上不能)安装。您收到的错误表明找不到应该作为子进程运行的 executable,而不是subprocess模块本身。可能是工作目录问题,$PATH,或者可执行文件不是.exe。 -
py.test是什么类型的文件? Windows 不知道它应该如何执行带有.test扩展名的文件,因此您至少需要指定一个解释器来执行它。有关git.cmd的此问题示例,请参阅this question。 -
试试
py.test.exe名字。 Windows 可能无法添加.exe后缀,因为它认为文件已经包含它(.test)。这是how Windows search for the executable file -
一个更新:只有在 IDEL (Python GUI) 甚至直接在 Windows dos shell 中执行时,我才会看到此错误。如果我在 GIT shell 中作为命令行执行它,它工作正常。
标签: python python-2.7 subprocess