Install python from source

You can put python from yum, but not always the latest version However, I don't like to increase the number of repositories unnecessarily, so I installed it from the source. The OS is CentOS 7.

# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

0. All steps

# cd /usr/local/src
# curl -O https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
# tar Jxf Python-3.6.2.tar.xz
# cd Python-3.6.2
# ./configure --prefix=/usr/local/python362 --with-ensurepip
# yum -y install zlib-devel openssl-devel tk-devel
# make
# make test
# make install
# ln -s /usr/local/python362/bin/python3.6 /bin/python3
# ln -s /usr/local/python362/bin/pip3.6 /bin/pip3

1. Get the latest version of the source

Is it troublesome to open the browser one by one? Search by curl. Suppress progress display with -s.

# curl -s https://www.python.org/downloads/source/ | grep -i latest
            <li><a href="/downloads/release/python-362/">Latest Python 3 Release - Python 3.6.2</a></li>
            <li><a href="/downloads/release/python-2713/">Latest Python 2 Release - Python 2.7.13</a></li>

The latest version is 3.6.2, so download it. -O is the same name as the remote and is output locally. Since it is a compilation before this, the location should be user / usr / local / src.

# cd /usr/local/src
# curl -O https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

Unzip. The xz format can be decompressed with the J option of tar.

# tar Jxf Python-3.6.2.tar.xz

2. Installation

Run configure. As for the installation destination, considering that the latest version will be installed later, I want to set it to / usr / local / python362, so specify prefix in configure. By the way, pip is used a lot, so specify to install it at the same time.

# cd Python-3.6.2
# ./configure --prefix=/usr/local/python362 --with-ensurepip

By executing configure, system libraries, commands, etc. Check what you need to compile and Create a Makefile that includes the prefix given as an option.

Next, install the pip prerequisite package (if not).

# yum -y install zlib-devel openssl-devel tk-devel

Next, compile based on the Makefile with make.

# make

Next, test if the make test works.

# make test
(Abbreviation)
zipimport.ZipImportError: can't decompress data; zlib not available
(Abbreviation)
Tests result: FAILURE
make: *** [test]Error 1

If it doesn't work, it looks like this. (Error when pip premise zlib is not included)

After SUCCESS, finally install with make install.

# make install

3. Create a link

Create links to python3 and pip3 under / bin.

# ln -s /usr/local/python362/bin/python3.6 /bin/python3
# ln -s /usr/local/python362/bin/pip3.6 /bin/pip3

Finally, display the version and check.

# python3 -V
Python 3.6.2
# pip3 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)

That's it.

4. Don't replace the link

** I was addicted to doing this at first, so I will leave it as a lesson. ** **

The existing link is a link to version 2, so switch this. By the way, I'll also make a pip link.

# which python
/bin/python
# ls -l /bin/python
lrwxrwxrwx.1 root root 7 May 2 13:00 /bin/python -> python2
# mv /bin/python /bin/_python
# ln -s /usr/local/python362/bin/python3.6 /bin/python
# ln -s /usr/local/python362/bin/pip3.6 /bin/pip

Finally, display the version and check.

# python -V
Python 3.6.2
# pip -V
pip 9.0.1 from /usr/local/python362/lib/python3.6/site-packages (python 3.6)

It didn't end with * ... *

Then I installed it and tried to put it in scipy with pip.

# pip install scipy
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Oh yeah, you need SSL. So let's put openssl-devel in yum. (* Actually, remake is required)

# yum -y install openssl-devel
  File "/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax

** (゜ ゜)… ** I got stuck with a face for a while. The reason is The way to write except has changed from Python3.

Therefore, shebang was changed as follows as a first aid measure. I don't really want to modify people's scripts, but ...

#!/usr/bin/python2

If you think it will work with

# yum -y install openssl-devel
(Abbreviation)
Downloading packages:
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax


It ends with the cancellation of the user

** Mata Omae? **

… So don't mess with the existing ones.

Recommended Posts

Install python from source
Install Python from source with Ansible
Install Apache 2.4.41 from source
install python
Install ansible from source code
Install pyenv from Homebrew, install Python from pyenv
Install vim7.3 (+ python2.4) from source (compatible with Gundo.vim)
Install Apache Maven (from source)
Compile and install Git from source.
Install Python locally
sql from python
Install NAOqi python
Install from conda-forge
MeCab from Python
Install Python Control
CentOS8 --Install --Python3
Install PostgreSQL from source code on CentOS
Touch MySQL from Python 3
Operate Filemaker from Python
How to install Python
Install Python on Pidora.
Install Scrapy on python3
Access bitcoind from python
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Python from or import
Build PostgreSQL from source
Use MySQL from Python
Install Python on Mac
Install Python 3 on Mac
Run python from excel
Install Python3.4 on CentOS 6.6
Execute command from Python
Install Python Jupyter lab
Install python external library
Operate neutron from Python!
Install python (pyenv, pyenv-virtualenv)
Install Voluptuous with Python 2.5
Install python on windows
Use MySQL from Python
Operate LXC from Python
Manipulate riak from python
Python PyTorch install tips
Force Python from Fortran
Install Python 2.7.3 on CentOS 5.4
Install python with pyenv
Use BigQuery from python.
Install Python 3.3 on Ubuntu 12.04
Install Python 3.4 on Mac
Execute command from python
[Python] Read From Stdin
Install Python 3.6 on Docker
Install Python (for Windows)
Use mecab-ipadic-neologd from python
[Python] Django Source Code Reading View Starting from Zero ①
Install the latest Python from pyenv installed with homebrew
Flatten using Python yield from
Call CPLEX from Python (DO cplex)
Post from Python to Slack
How to install Python [Windows]
Install watchdog on Windows + Python 3.3