我正在尝试创建一个 boostrap.py 脚本,该脚本将创建 virtualenv 并安装requirements.txt 文件中的需求。我的项目的其他贡献者应该能够从 github checkout 该项目并运行 python bootstrap.py ,然后运行 source env/bin/activate 来安装我的应用程序。以下是我使用此页面作为指南编写的脚本:http://pypi.python.org/pypi/virtualenv
import virtualenv, textwrap
output = virtualenv.create_bootstrap_script(textwrap.dedent("""
def after_install(options, home_dir):
if sys.platform == 'win32':
bin = 'Scripts'
else:
bin = 'bin'
subprocess.call([join(home_dir,bin,'pip'),'install -r requirements.txt'])
"""))
print output
下面是我为了创建 Bootstrap 并运行它而运行的命令:
python create_bootstrap.py > bootstrap.py
python bootstrap.py env
下面是输出:
New python executable in env/bin/python
Installing setuptools............done.
Installing pip...............done.
Usage: pip COMMAND [OPTIONS]
pip: error: No command by the name pip install -r requirements.txt
(maybe you meant "pip install install -r requirements.txt")
requirements.txt 如下所示:
sqlalchemy==0.7
任何关于不同实践的建议或关于我做错了什么的提示都会有帮助。非常感谢!
最佳答案
在
subprocess.call([join(home_dir,bin,'pip'),'install -r requirements.txt'])
'install -rrequirements.txt'
被视为包含空格的单个参数,因此子进程模块将其解释为对 pip'install-rrequirements.txt 的调用'
。
您可以通过单独指定每个参数来解决此问题:
subprocess.call([join(home_dir,bin,'pip'), 'install', '-r', 'requirements.txt'])
关于python - 运行后`pip: error: No command by the name pip install -r requirements.txt`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8370215/