1

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.

Jeetendra Pujari
  • 1,286
  • 2
  • 17
  • 31
  • not so a python, but the log pastes does suggest that its already there (3.5). the python2.7 might be the default system python that ships with centos/rhel 7 – OK999 Dec 21 '16 at 17:59

2 Answers2

2

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.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Got it. Is there way to enable it globally? the cookbook only installs the package. – Jeetendra Pujari Dec 21 '16 at 19:19
  • It is global within Chef when you use the other resources from poise-python. Unfortunately you cannot simply add SCL package binaries to your path if that's what you mean. – coderanger Dec 21 '16 at 19:29
0

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.

Jyoti Dhiman
  • 540
  • 2
  • 6
  • 17