Python

使用 Chef 的 application_python 食譜指定 virtualenv python 版本

  • June 27, 2012

我正在使用 Opscode 的application_python食譜,並嘗試部署 Django 應用程序。我需要為這個項目使用 Python 2.7,但似乎python2.6預設情況下已經完成了 virtualenv 創建,我不打算在系統上安裝它。因此,執行時出現以下錯誤chef-client

[Fri, 08 Jun 2012 16:55:35 +0000] FATAL: Mixlib::ShellOut::ShellCommandFailed: execute[virtualenv --python=python2.6 /opt/apps/trippingbear/shared/env] (/var/chef/cache/cookbooks/python/providers/virtualenv.rb line 28) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '3'
---- Begin output of virtualenv --python=python2.6 /opt/apps/trippingbear/shared/env ----
STDOUT: The executable python2.6 (from --python=python2.6) does not exist
STDERR: 
---- End output of virtualenv --python=python2.6 /opt/apps/trippingbear/shared/env ----
Ran virtualenv --python=python2.6 /opt/apps/trippingbear/shared/env returned 3

我對廚師很(非常)新,並且不知道如何改變它。預設值似乎是用attribute :interpreter, :default => 'python2.6'in設置的cookbooks/python/resources/virtualenv.rb。我嘗試在我的節點和環境中設置預設值,如下所示,但沒有成功:

default_attributes(
 "python" => {
   "virtualenv" => {
     "interpreter" => "python2.7"
   }
 }
)

我確定這是可配置的,但我不知道該怎麼做。我設置不正確?

我總是在我的部署配方中明確創建我的 virtualenv,然後根據需要引用該 virtualenv。例如:

venv_dir = node['some_identifier']['virtualenv_dir']

python_virtualenv venv_dir do
   interpreter "python"            # use system default python, not 2.6
   action :create
end 

python_pip "django" do
   version "1.4"
   action :install
   virtualenv venv_dir
end

顯然,這是使用 Python 食譜中的python_virtualenv資源,因此需要將 Python 食譜列為您的食譜中的依賴項。

引用自:https://serverfault.com/questions/396990