繁体   English   中英

使用Chef时,“ pip install -r requirements.txt”失败

[英]'pip install -r requirements.txt' fails when using Chef

我有一个脚本已复制到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

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

看起来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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM