【问题标题】:'pip install -r requirements.txt' fails when using Chef使用 Chef 时“pip install -r requirements.txt”失败
【发布时间】:2016-07-20 08:10:24
【问题描述】:

我有一个复制到 Chef 节点的脚本;它会激活一个 python 虚拟环境,然后从需求文件中安装需求:

#!/bin/bash
source venv/bin/activate
pip install -v -r requirements.txt >> scripts/scripts.out

当我在本地运行它时,一切都很好。当使用 Chef 执行块 (bash) 运行时,它会静默失败。

bash 'install_dependencies' do
        cwd '/opt/application/'
        user 'app-user'
        code <<-EOH
                ./scripts/install-deps.sh
                EOH
end

有什么建议吗?这是失败的输出:

Collecting bs4 (from -r requirements.txt (line 4))
  1 location(s) to search for versions of bs4:
  * https://pypi.python.org/simple/bs4/
  Getting page https://pypi.python.org/simple/bs4/
  Looking up "https://pypi.python.org/simple/bs4/" in the cache
  No cache entry available
  Starting new HTTPS connection (1): pypi.python.org
  "GET /simple/bs4/ HTTP/1.1" 200 313
  Updating cache with response from "https://pypi.python.org/simple/bs4/"
  Caching b/c date exists and max-age > 0
  Analyzing links from page https://pypi.python.org/simple/bs4/
    Found link https://pypi.python.org/packages/10/ed/7e8b97591f6f456174139ec089c769f89a94a1a4025fe967691de971f314/bs4-0.0.1.tar.gz#md5=fe7e51587ac3b174608f3c4f8bd893ac (from https://pypi.python.org/simple/bs4/), version: 0.0.1
    Found link https://pypi.python.org/packages/50/fe/c4bf5083af20ec85ac5d278dfd12a9756724100c308b7bdccbaa7cbf5715/bs4-0.0.0.tar.gz#md5=c1b62a2b9f2987d7f949f1392a82518f (from https://pypi.python.org/simple/bs4/), version: 0.0.0
  Using version 0.0.1 (newest of versions: 0.0.0, 0.0.1)
Cleaning up...

以及(成功的)本地运行的输出头 - 即它继续完成安装:

Collecting bs4 (from -r requirements.txt (line 4))
  1 location(s) to search for versions of bs4:
  * https://pypi.python.org/simple/bs4/
  Getting page https://pypi.python.org/simple/bs4/
  Looking up "https://pypi.python.org/simple/bs4/" in the cache
  Current age based on date: 558
  Freshness lifetime from max-age: 600
  Freshness lifetime from request max-age: 600
  The response is "fresh", returning cached response
  600 > 558
  Analyzing links from page https://pypi.python.org/simple/bs4/
    Found link https://pypi.python.org/packages/10/ed/7e8b97591f6f456174139ec089c769f89a94a1a4025fe967691de971f314/bs4-0.0.1.tar.gz#md5=fe7e51587ac3b1
    Found link https://pypi.python.org/packages/50/fe/c4bf5083af20ec85ac5d278dfd12a9756724100c308b7bdccbaa7cbf5715/bs4-0.0.0.tar.gz#md5=c1b62a2b9f2987
  Using version 0.0.1 (newest of versions: 0.0.0, 0.0.1)
  Using cached wheel link: file:///ridl/.cache/pip/wheels/84/67/d4/9e09d9d5adede2ee1c7b7e8775ba3fbb04d07c4f946f0e4f11/bs4-0.0.1-cp34-none-any.whl
Collecting requests (from -r requirements.txt (line 5))
  1 location(s) to search for versions of requests:
  * https://pypi.python.org/simple/requests/
  Getting page https://pypi.python.org/simple/requests/
  Looking up "https://pypi.python.org/simple/requests/" in the cache
  Current age based on date: 558
  Freshness lifetime from max-age: 600
  Freshness lifetime from request max-age: 600
  The response is "fresh", returning cached response
  600 > 558
  Analyzing links from page https://pypi.python.org/simple/requests/
    Found link https://pypi.python.org/packages/00/c8/8cf0f078100ce5fe7ff35927d8861e2e36daed9be2db56690f3ad80ccec4/requests-0.7.1.tar.gz#md5=4821c6902
    Found link https://pypi.python.org/packages/01/44/39988315e036b79fe70428273053617266bf20d1363e91082346fae8450d/requests-0.10.3.tar.gz#md5=a055af00
    Found link https://pypi.python.org/packages/01/da/da83c242c5a77c58aa86072d68fd2855aa9b4d3b1a8bac4b402531b25ff1/requests-0.13.9.tar.gz#md5=66d52b8f
    Found link https://pypi.python.org/packages/02/56/a6203485b552f9e8e8f16bd4e576446f94737ccbc563957e7510c8e401e4/requests-0.13.6.tar.gz#md5=9ea0f38c

【问题讨论】:

    标签: python pip chef-infra


    【解决方案1】:

    您还可以使用 poise-python 食谱中的 pip_requirements 资源,它会为您完成所有这些工作。

    【讨论】:

    • 开个玩笑,这基本上是我一直试图重新发明的——接受你的回答......
    【解决方案2】:

    看起来 Chef 的 bash 块没有为其所代表的用户设置主目录。结果 pip 无法找到/使​​用缓存目录。在脚本中明确说明它解决了问题:

    #!/bin/bash
    source venv/bin/activate
    pip install -v -r requirements.txt --cache-dir /home/app-user/.cache/pip >> scripts/scripts.out
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-27
    • 2016-04-26
    • 1970-01-01
    • 2012-10-01
    相关资源
    最近更新 更多