Install Python from source with Ansible

I would like to install Python 2.7.10 from source on CentOS using Ansible. This time it is Python, but if you use it, you can use it to install other libraries.

What you want to do (command)

Here's what I want to do. / usr / local / is specified as the installation destination, and / var / tmp / is specified as the temporary save destination of the source.

yum install gcc
wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz -P /var/tmp/
tar xvzf /var/tmp/Python-2.7.10.tgz -C /var/tmp/
cd /var/tmp/Python-2.7.10/
./configure CFLAGS=-fPIC --enable-shared --prefix=/usr/local/
make
make install
ln /usr/local/lib/libpython2.7.so.1.0 /lib64/libpython2.7.so.1.0

I'm also installing gcc as it may cause an error when I run configure. I installed it when I ran make install, but I got an error when I ran the installed Python, so I put a symbolic link at the end.

Reference: [Python error handling: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory](http://kenzo0107.hatenablog.com/entry/2015/02/ 17/114506)

playbook

Source

- hosts: all
  become: yes
  tasks:

    - name: Install gcc
      yum: name=gcc state=latest

    - name: Create tmp directory
      file: path=/var/tmp/Python-2.7.10 state=directory

    - name: Download Python
      get_url: >
        url=https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
        dest=/var/tmp/Python-2.7.10.tgz
        creates=/usr/local/bin/python
      environment:
        LANG: C
        LC_ALL: C
        LC_MESSAGES: C

    - name: Unarchive Python
      unarchive: src=/var/tmp/Python-2.7.10.tgz dest=/var/tmp/ copy=no

    - name: Install Python
      command: >
        {{ item }}
        chdir=/var/tmp/Python-2.7.10/
        creates=/usr/local/bin/python
      with_items:
        - './configure CFLAGS=-fPIC --enable-shared --prefix=/usr/local/'
        - make
        - make install

    - name: Link Python lib
      file: src=/usr/local/lib/libpython2.7.so.1.0 dest=/lib64/libpython2.7.so.1.0 state=link

Description

Install gcc

As mentioned above, if there is no gcc, an error will occur, so I installed it with yum.

Create tmp directory

When I ran ʻUnarchive Python` after this, I needed the destination directory, so I created it here in advance.

Download Python

Download the Python source. If it already exists, it will not be downloaded.

Unarchive Python

Unzip tgz. If copy = yes, it refers to the file of the host running Ansible. This time, I set copy = no because I want to refer to the file on the server. When I did this, I ran into the error'No such file or directory'even though the file should exist, so I added ʻenvironment`.

Reference: No such file or directory in Ansible unarchive

Install Python

Here, we just use command to execute configure, make, and make install. At that time, chdir is used to move to the directory where the source is located. I used these commands a lot, so I thought they were the default features of Ansible, but when I looked them up, I wasn't sure. If creates is specified and / usr / local / bin / python already exists, it will be skipped.

Link Python lib

A symbolic link is attached as a countermeasure for the error written at the beginning.

Recommended Posts

Install Python from source with Ansible
Install python from source
Install ansible from source code
Install vim7.3 (+ python2.4) from source (compatible with Gundo.vim)
Install Apache 2.4.41 from source
Install Voluptuous with Python 2.5
Install python with pyenv
[Ansible] Install dnf on Centos7 with Python3 interpreter
Install Python environment with Anaconda
Install external libraries with Python
Install pyenv from Homebrew, install Python from pyenv
With skype, notify with skype from python!
Install Apache Maven (from source)
Install the latest Python from pyenv installed with homebrew
Call C from Python with DragonFFI
Install Python 2.7.9 and Python 3.4.x with pip.
Using Rstan from Python with PypeR
I can't install python3 with pyenv-vertualenv
install python
Create folders from '01' to '12' with python
Put postfix 2.11 in source with ansible
Install the Python plugin with Netbeans 8.0.2
Run Aprili from Python with Orange
Install Ansible
Unable to install Python with pyenv
Call python from nim with Nimpy
Compile and install Git from source.
Run Ansible from Python using API
Read fbx from python with cinema4d
Install python with mac vs code
[Python Windows] pip install with Python version
Collecting information from Twitter with Python (Twitter API)
Receive textual data from mysql with python
Get html from element with Python selenium
[Note] Get data from PostgreSQL with Python
Create wordcloud from your tweet with python3
Install Python as a Framework with pyenv
Add a Python data source with Redash
Tweet from python with Twitter Developer + Tweepy
Business efficiency starting from scratch with Python
Decrypt files encrypted with openssl from python with openssl
Working with Azure CosmosDB from Python Part.2
scipy stumbles with pip install on python 2.7.8
Image acquisition from camera with Python + OpenCV
Getting started with Dynamo from Python boto
Try calling Python from Ruby with thrift
Scraping from an authenticated site with python
Use C ++ functions from python with pybind11
Install PostgreSQL from source code on CentOS
How to install python3 with docker centos
FizzBuzz with Python3
Scraping with Python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Install Python locally
Play with 2016-Python
sql from python
AES256 with python
Tested with Python