How to install python 3.5 in chef

2.6k Views Asked by At

I am trying to install python 3.5 in a chef recipe. I tried using the poise-python cookbook. After reading the documentation. I tried the following command, but it doesn't install python 3.5. It installs python2.7

python_runtime 'python3' do
version '3.5'
end

The output

 * python_runtime[python3] action install
   * poise_languages_scl[rh-python35] action install
     * yum_package[centos-release-scl-rh] action upgrade
- upgrade package centos-release-scl-rh from uninstalled to 2-2.el7.centos
     * ruby_block[flush_yum_cache] action run
- execute the ruby block flush_yum_cache
     * yum_package[rh-python35] action install
- install version 2.0-2.el7 of package rh-python35
     * yum_package[rh-python35-python-devel] action install (up to date)

   * python_runtime_pip[python3] action install (up to date)
   * python_package[setuptools] action install (up to date)
   * python_package[wheel] action install
     - install version 0.29.0 of package wheel

Any help would be appreciated. I can go the route of using execute to run the install commands but would prefer to use a cookbook.

2

There are 2 best solutions below

2
On BEST ANSWER

As you can see in the log, it is installing 3.5 via the SCL packages. I'm guessing you are thinking it is 2.7 because you're running /usr/bin/python -v manually afterwards. That is not how you use SCL packages, run scl enable rh-python35 "python -v" and you'll see 3.5. The cookbook does this for you internally.

0
On

Another alternative would be to create a virtual env using python_runtime like:

python_runtime 'python2' do
  version '2.7'
  action :install
end

python_virtualenv "/mnt/env/python2" do
 user "root"
 python 'python2'
 action :create
end

And now if you activate virtualenv:

source /mnt/env/python2/bin/activate

And check python version:

python -v

It will be the same as installed.