python - 运行后`pip: error: No command by the name pip install -r requirements.txt`

标签 python virtualenv bootstrapping

我正在尝试创建一个 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/

相关文章:

python - Pact:如何设置提供者状态

python - 用于 Jenkins/本地构建的 PyPI 本地缓存

grails - 初始化应用程序时出错:无此类属性:类的 session :BootStrap

php - 表单无法使用mysql获取php中的值

angular - Angular 可以有多个 Bootstrap 组件吗?

python - 如何使用json序列化对象

python - Flask FileStorage 保存空文件

python - 如何正确弃用 Python 中的自定义异常?

python - 如何从 Heroku/Cedar 的 virtualenv 中清除陈旧的 pypi 包?

python - 如何并行安装 python2 和 python3 的 pylint