Reputation: 175
As an absolute Chef beginner I try to set up a vm with the latest python and django. I use the "ubuntu/trusty64" box and was surprised that its python3 version does not come with pip and pyvenv installed. So I had to install the latest python version 3.4.3 from source, which seems to be working fine. But when trying to pip install django with chef, I always get the same error saying:
Chef::Exceptions::Package: No candidate version available for django
my python3 recipe:
package "python"
execute "update system" do
command "sudo apt-get update -y"
not_if { File.exists?('/tmp/Python-3.4.3')}
end
execute "get dependencies" do
command "sudo apt-get install -y build-essential libbz2-dev libncurses5-dev libreadline6-dev libsqlite3-dev libgdbm-dev liblzma-dev tk8.6-dev libssl-dev python3-setuptools"
not_if { File.exists?('/tmp/Python-3.4.3')}
end
%w[ /opt/python /djenv ].each do |path|
directory path do
owner 'vagrant'
group 'vagrant'
mode '0755'
end
end
bash 'install-python3.4.3' do
user 'vagrant'
cwd '/tmp'
code <<-EOH
set -e
wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tgz
tar -xvf Python-3.4.3.tgz
rm Python-3.4.3.tgz
cd Python-3.4.3
./configure --prefix=/opt/python
make
make install
EOH
not_if { File.exists?('/tmp/Python-3.4.3')}
end
execute "set pyvenv environment to /djenv" do
command "/opt/python/bin/pyvenv /djenv"
only_if{File.exists?('/opt/python/bin/python3')}
end
the django recipe:
package 'django'
execute "activate env" do
command "source /djenv/bin/activate"
end
execute "install django and gunicorn" do
command "pip install gunicorn && pip install Django==1.8.3"
not_if {File.exists('/vagrant/../manage.py')}
end
execute "deactivate" do
command "deactivate"
end
I basicaly follow this tutorial and try to translate it into chef.
Upvotes: 0
Views: 395
Reputation: 21226
package 'python3' #will install python
package 'python3-pip' #will install pip3
execute 'pip3 install django' do #install django from command line with pip
not_if "pip3 list | grep django" #only if it is not installed yet
end
execute 'pip3 install gunicorn' do
not_if "pip3 list | grep gunicorn"
end
Upvotes: 1