Python 带子进程的pip冻结调用-无此类文件或目录

Python 带子进程的pip冻结调用-无此类文件或目录,python,python-2.7,subprocess,pip,Python,Python 2.7,Subprocess,Pip,我试图从Python脚本(Python 2.7,Ubuntu 14.04)中编写一个requirements.txt文件。按照建议,我试了一下 但出于我不知道的原因,我得到了一个错误: OSError: [Errno 2] No such file or directory 运行脚本的文件夹是可写的。什么会导致这个问题 试试这个: import subprocess with open("requirements.txt", "w") as f: subprocess.call(["

我试图从Python脚本(Python 2.7,Ubuntu 14.04)中编写一个
requirements.txt
文件。按照建议,我试了一下

但出于我不知道的原因,我得到了一个错误:

OSError: [Errno 2] No such file or directory
运行脚本的文件夹是可写的。什么会导致这个问题

试试这个:

import subprocess

with open("requirements.txt", "w") as f:
    subprocess.call(["pip", "freeze"], stdout=f)
“无此类文件”的意思是“pip冻结”。您引用的示例没有详细说明如何传递命令行参数

import subprocess

with open("requirements.txt", "w") as f:
    subprocess.call(["pip", "freeze"], stdout=f)