【问题标题】:NameError : uninitialized constant Chef::Resource::PythonPipNameError : 未初始化的常量 Chef::Resource::PythonPip
【发布时间】:2017-11-22 09:46:03
【问题描述】:

我正在关注《挖掘社交媒体》第 2 版一书,以便在 Twitter 上做一些数据科学。我下载了包含必要文件和文件夹等的文件...... 在尝试流浪时(它使用 Vagrant 来控制将执行一些 ipython 笔记本的 VM(virtualBox vm)),我发现了一个奇怪的错误: NoNameError: uninitialized constant Chef::Resource::PythonPip 这是 default.tb 文件: 默认['python']['install_method'] = 'package'

if node['python']['install_method'] == 'package'
  case node['platform']
  when "smartos"
   default['python']['prefix_dir']         = '/opt/local'
  else
    default['python']['prefix_dir']         = '/usr'
  end
else
  default['python']['prefix_dir']         = '/usr/local'
end

default['python']['binary'] = "#{node['python']
['prefix_dir']}/bin/python"

default['python']['url'] = 'http://www.python.org/ftp/python'
default['python']['version'] = '2.7.7'
default['python']['checksum'] = 
'3b477554864e616a041ee4d7cef9849751770bc7c39adaf78a94ea145c488059'
default['python']['configure_options'] = %W{--prefix=#{node['python']
['prefix_dir']}}

default['python']['setuptools_script_url'] = 
'https://bitbucket.org/pypa/setuptools/raw/0.8/ez_setup.py'
default['python']['pip_script_url'] = 'https://bootstrap.pypa.io/get-
pip.py'

这里是 /deploy/python/providers/pip.rb(它识别出错误的地方)

require 'chef/mixin/shell_out'
require 'chef/mixin/language'
include Chef::Mixin::ShellOut

def whyrun_supported?
  true
end

# the logic in all action methods mirror that of
# the Chef::Provider::Package which will make
# refactoring into core chef easy

action :install do
  # If we specified a version, and it's not the current version, move 
to the specified version
  if new_resource.version != nil && new_resource.version != 
current_resource.version
    install_version = new_resource.version
  # If it's not installed at all, install it
  elsif current_resource.version == nil
    install_version = candidate_version
  end

  if install_version
    description = "install package #{new_resource} version #
{install_version}"
    converge_by(description) do
      Chef::Log.info("Installing #{new_resource} version #
{install_version}")
      status = install_package(install_version)
      if status
        new_resource.updated_by_last_action(true)
      end
    end
  end
end

action :upgrade do
  if current_resource.version != candidate_version
    orig_version = current_resource.version || "uninstalled"
    description = "upgrade #{current_resource} version from #
{current_resource.version} to #{candidate_version}"
    converge_by(description) do
      Chef::Log.info("Upgrading #{new_resource} version from #
{orig_version} to #{candidate_version}")
      status = upgrade_package(candidate_version)
      if status
        new_resource.updated_by_last_action(true)
      end
    end
  end
end

action :remove do
  if removing_package?
   description = "remove package #{new_resource}"
   converge_by(description) do
     Chef::Log.info("Removing #{new_resource}")
      remove_package(new_resource.version)
     new_resource.updated_by_last_action(true)
    end

【问题讨论】:

    标签: python ruby pip chef-infra


    【解决方案1】:

    更改为 poise-python 是最好的解决方案,但可以修补旧的 python 食谱。了解为什么会发生此错误可能有助于其他人在迁移到 Chef 13 时在自定义食谱中遇到类似问题。

    Chef 13 不再为自定义资源创建模块常量,如发行说明 https://discourse.chef.io/t/chef-client-13-released/10735 中所述

    在贬值的 python 食谱中只需要更改两行代码,因此它适用于 chef 13。

    在 providers/virtualenv.rb 中:

    -  @current_resource = Chef::Resource::PythonVirtualenv.new(new_resource.name)
    +  @current_resource = Chef::Resource.resource_for_node(:python_virtualenv, node).new(new_resource.name)
    

    在 providers/pip.rb 中:

    -  @current_resource = Chef::Resource::PythonPip.new(new_resource.name)
    +  @current_resource = ::Chef::Resource.resource_for_node(:python_pip, node).new(new_resource.name)
    

    【讨论】:

      【解决方案2】:

      python 食谱明确标记为已弃用,Chef 13 根本不支持(或一般情况下,但我不会为 Chef 13 修复它)。请改用poise-python

      【讨论】:

      • 你能告诉我我该怎么做吗???用 poise-python (来自 Git)替换 python 文件夹???我认为这可能是“已弃用的东西”,但我没有发现问题
      • 如果您刚开始使用 Chef,我建议您阅读 learn.chef.io 教程。 poise-python 升级不是直接替代品,但很接近。 poise-python 自述文件中有升级指南。
      • 事实上,当我尝试 vagrant up 时,它告诉我一个奇怪的错误: Missing Cookbooks: default: Could not meet version constraints for: python which may have questions with upgrade ,文件自述文件可以帮助我吗?因为我没有足够的时间来学习教程并搜索它
      • 如果您没有时间学习教程,那么没有,我帮不了您。无论您尝试做什么都不适用于 Chef 13。
      • 您不能帮助解决我遇到的错误吗?我认为“python”的使用和新的称谓 poise-python 之间存在问题
      猜你喜欢
      • 2014-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-19
      • 2015-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多