epelレポからpython3.6.8 install

動機

bashでwebサイト作成してあと、pythonでもつくろうとおもっているから、install。

参考文献

CentOS に Python2.7, Python3を入れたメモ  
ファイルの圧縮、解凍方法  
pyenvで3.7系のインストールに失敗したときのメモ  
Pythonの対話モードの履歴と矢印キー  
PythonのインタプリタでCtrl-Lや矢印が使えないときの解決方法  

パッケージのダウンロード

コード表示

[oracle@centos unko]$ python --version
Python 2.7.5
[oracle@centos unko]$ which python
/usr/bin/python
[oracle@centos unko]$ curl -LO https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 16.3M  100 16.3M    0     0  1820k      0  0:00:09  0:00:09 --:--:-- 2117k
[oracle@centos unko]$ ll
合計 16732
-rw-r--r--. 1 oracle docker 17131432  7月 23 22:33 Python-3.7.4.tar.xz
[oracle@centos unko]$ tar -xvf Python-3.7.4.tar.xz
[oracle@centos unko]$ ll
合計 16736
drwxr-xr-x. 18 oracle docker     4096  7月  9 03:31 Python-3.7.4
-rw-r--r--.  1 oracle docker 17131432  7月 23 22:33 Python-3.7.4.tar.xz

makeする

エラーになった。

コード表示

[oracle@centos unko]$ cd Python-3.7.4
[oracle@centos Python-3.7.4]$ ll
合計 1060
-rw-r--r--.  1 oracle docker    631  7月  9 03:03 CODE_OF_CONDUCT.rst
drwxr-xr-x. 18 oracle docker   4096  7月  9 03:31 Doc
drwxr-xr-x.  2 oracle docker   4096  7月  9 03:03 Grammar
drwxr-xr-x.  3 oracle docker   4096  7月  9 03:03 Include
-rw-r--r--.  1 oracle docker  12769  7月  9 03:03 LICENSE
drwxr-xr-x. 33 oracle docker   4096  7月  9 03:03 Lib
drwxr-xr-x.  8 oracle docker   4096  7月  9 03:03 Mac
-rw-r--r--.  1 oracle docker  63658  7月  9 03:03 Makefile.pre.in
drwxr-xr-x.  2 oracle docker   4096  7月  9 03:31 Misc
drwxr-xr-x. 13 oracle docker   4096  7月  9 03:03 Modules
drwxr-xr-x.  4 oracle docker   4096  7月  9 03:03 Objects
drwxr-xr-x.  6 oracle docker   4096  7月  9 03:03 PC
drwxr-xr-x.  2 oracle docker   4096  7月  9 03:03 PCbuild
drwxr-xr-x.  2 oracle docker   4096  7月  9 03:03 Parser
drwxr-xr-x.  2 oracle docker   4096  7月  9 03:03 Programs
drwxr-xr-x.  3 oracle docker   4096  7月  9 03:03 Python
-rw-r--r--.  1 oracle docker  10113  7月  9 03:03 README.rst
drwxr-xr-x. 23 oracle docker   4096  7月  9 03:03 Tools
-rw-r--r--.  1 oracle docker  10953  7月  9 03:03 aclocal.m4
-rwxr-xr-x.  1 oracle docker  44166  7月  9 03:03 config.guess
-rwxr-xr-x.  1 oracle docker  36251  7月  9 03:03 config.sub
-rwxr-xr-x.  1 oracle docker 503641  7月  9 03:03 configure
-rw-r--r--.  1 oracle docker 167840  7月  9 03:03 configure.ac
-rwxr-xr-x.  1 oracle docker   7122  7月  9 03:03 install-sh
drwxr-xr-x.  2 oracle docker   4096  7月  9 03:03 m4
-rw-r--r--.  1 oracle docker  43204  7月  9 03:03 pyconfig.h.in
-rw-r--r--.  1 oracle docker 103776  7月  9 03:03 setup.py
[oracle@centos Python-3.7.4]$ ./configure --with-ensurepip
Traceback (most recent call last):
  File "/home/oracle/unko/Python-3.7.4/Lib/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/oracle/unko/Python-3.7.4/Lib/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/oracle/unko/Python-3.7.4/Lib/ensurepip/__main__.py", line 5, in 
    sys.exit(ensurepip._main())
  File "/home/oracle/unko/Python-3.7.4/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/home/oracle/unko/Python-3.7.4/Lib/ensurepip/__init__.py", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/home/oracle/unko/Python-3.7.4/Lib/ensurepip/__init__.py", line 27, in _run_pip
    import pip._internal
  File "/tmp/tmp0ezzadqo/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/__init__.py", line 40, in 
  File "/tmp/tmp0ezzadqo/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py", line 8, in 
  File "/tmp/tmp0ezzadqo/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 12, in 
  File "/tmp/tmp0ezzadqo/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/__init__.py", line 6, in 
  File "/tmp/tmp0ezzadqo/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/completion.py", line 6, in 
  File "/tmp/tmp0ezzadqo/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 20, in 
  File "/tmp/tmp0ezzadqo/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/download.py", line 37, in 
  File "/tmp/tmp0ezzadqo/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in 
  File "/home/oracle/unko/Python-3.7.4/Lib/ctypes/__init__.py", line 7, in 
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
make: *** [install] エラー 1

libffi-develいんすこ

コード表示

[oracle@centos Python-3.7.4]$ sudo yum install -y libffi-devel

再いんすこ

alias python=”/usr/local/bin/python3″を追加。~/.bashrcに。

コード表示

[oracle@centos Python-3.7.4]$ make
[oracle@centos Python-3.7.4]$ sudo make install
Looking in links: /tmp/tmpdo_t739u
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.0.3 setuptools-40.8.0
[oracle@centos Python-3.7.4]$ ls -l /usr/bin/ | grep python2.7
lrwxrwxrwx.   1 root root           9  7月  1 21:58 python2 -> python2.7
lrwxrwxrwx.   1 root root          16  7月  1 21:58 python2-config -> python2.7-config
-rwxr-xr-x.   1 root root        7216  6月 21 05:28 python2.7
-rwxr-xr-x.   1 root root        1835  6月 21 05:27 python2.7-config
[oracle@centos Python-3.7.4]$ ls -l /usr/local/bin/ | grep python
lrwxrwxrwx. 1 root root        9  7月 23 22:53 python3 -> python3.7
lrwxrwxrwx. 1 root root       16  7月 23 22:53 python3-config -> python3.7-config
-rwxr-xr-x. 2 root root 13988344  7月 23 22:53 python3.7
lrwxrwxrwx. 1 root root       17  7月 23 22:53 python3.7-config -> python3.7m-config
-rwxr-xr-x. 2 root root 13988344  7月 23 22:53 python3.7m
-rwxr-xr-x. 1 root root     2902  7月 23 22:53 python3.7m-config
[oracle@centos Python-3.7.4]$ cat ~/.bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

alias unkommit="/usr/local/bin/unkommit.sh"
alias awk="/usr/local/bin/awk"
alias gawk="/usr/local/bin/awk"
alias python="/usr/local/bin/python3"
alias la="ls -la"
LANG=ja_JP.utf8


[oracle@centos Python-3.7.4]$ . ~/.bashrc

[oracle@centos Python-3.7.4]$ python --version
Python 3.7.4

動作確認

CTRL+Dでinteractiveモード抜ける。

コード表示

[oracle@centos ~]$ python
Python 3.7.4 (default, Jul 23 2019, 22:53:28) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('unko')
unko

追記

6.51.1. Python 3 のインストール

pipというパッケージ管理用コマンドが入っていなかったため、再実行

コード表示

[oracle@centos Python-3.7.4]$ sudo yum -y install openssl
[oracle@centos Python-3.7.4]$ openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017
[oracle@centos Python-3.7.4]$ ./configure --prefix=/usr                   --enable-shared                 --with-system-expat             --with-system-ffi               --with-ensurepip=yes
[oracle@centos Python-3.7.4]$ make
[oracle@centos Python-3.7.4]$ sudo make install
[oracle@centos bin]$ pwd
/usr/bin
[oracle@centos bin]$ ll | grep pip
-rwxr-xr-x.   1 root root        2291  7月 31  2015 lesspipe.sh
-rwxr-xr-x.   1 root root       11424  2月 26  2014 mispipe
-rwxr-xr-x.   1 root root         281  6月 15  2016 pip
-rwxr-xr-x.   1 root root         283  6月 15  2016 pip2
-rwxr-xr-x.   1 root root         287  6月 15  2016 pip2.7
lrwxrwxrwx.   1 root root           6  7月 24 06:50 pip3 -> pip3.7
-rwxr-xr-x.   1 root root         217  7月 24 06:43 pip3.7
[oracle@centos Python-3.7.4]$ pip -V
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
[oracle@centos Python-3.7.4]$ sudo chmod -v 755 /usr/lib/libpython3.7m.so
[sudo] oracle のパスワード:
`/usr/lib/libpython3.7m.so' のモードを 0555 (r-xr-xr-x) から 0755 (rwxr-xr-x) へ変更しました
[oracle@centos Python-3.7.4]$ sudo chmod -v 755 /usr/lib/libpython3.so
`/usr/lib/libpython3.so' のモードを 0555 (r-xr-xr-x) から 0755 (rwxr-xr-x) へ変更しました
[oracle@centos Python-3.7.4]$ sudo ln -sfv pip3.7 /usr/bin/pip3
`/usr/bin/pip3' -> `pip3.7'
[oracle@centos bin]$ vi ~/.bashrc
[oracle@centos bin]$ cat ~/.bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

alias unkommit="/usr/local/bin/unkommit.sh"
alias awk="/usr/local/bin/awk"
alias gawk="/usr/local/bin/awk"
alias python="/usr/local/bin/python3"
alias pip="/usr/bin/pip3.7"
alias la="ls -la"
LANG=ja_JP.utf8
[oracle@centos bin]$ . ~/.bashrc

よくわからんところ

コード表示

[oracle@centos bin]$ pwd
/usr/bin
[oracle@centos bin]$ pip3.7 -V
pip 19.0.3 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
[oracle@centos bin]$ /usr/bin/pip3.7 -V
/usr/bin/python3.7: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory
[oracle@centos ~]$ pip3 -V
pip 19.0.3 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
[oracle@centos ~]$ pip3.7 -V
pip 19.0.3 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
[oracle@centos ~]$ pip -V
/usr/bin/python3.7: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory

make install時にこのログでた。あとで見直す。

コード表示

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_curses               _curses_panel         _dbm               
_gdbm                 _hashlib              _sqlite3           
_ssl                  readline                                 
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  atexit                pwd                
time                                                           

めんど臭くなってepelレポからいれちゃいました。

CentOS7でpython3をepelから入れる
コード表示

[root@centos Python-3.7.4]# yum info python36
読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * centos-qemu-ev: ftp.tsukuba.wide.ad.jp
 * epel: ftp.riken.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
利用可能なパッケージ
名前                : python36
アーキテクチャー    : x86_64
バージョン          : 3.6.8
リリース            : 1.el7
容量                : 67 k
リポジトリー        : epel/x86_64
要約                : Interpreter of the Python programming language
URL                 : https://www.python.org/
ライセンス          : Python
説明                : Python is an accessible, high-level, dynamically typed, interpreted programming
                    : language, designed with an emphasis on code readability.
                    : It includes an extensive standard library, and has a vast ecosystem of
                    : third-party libraries.
                    : 
                    : The python36 package provides the "python3" executable: the reference
                    : interpreter for the Python language, version 3.
                    : The majority of its standard library is provided in the python36-libs package,
                    : which should be installed automatically along with python36.
                    : The remaining parts of the Python standard library are broken out into the
                    : python36-tkinter and python36-test packages, which may need to be installed
                    : separately.
                    : 
                    : Documentation for Python is provided in the python36-docs package.
                    : 
                    : Packages containing additional libraries for Python are generally named with
                    : the "python36-" prefix.
[root@centos Python-3.7.4]# yum install python36 python36-devel python36-libs

[root@centos Python-3.7.4]# python36 --version
Python 3.6.8

[oracle@centos ~]$ python36 --version
Python 3.6.8
[oracle@centos ~]$ python --version
Python 3.6.8


[oracle@centos ~]$ python
Python 3.6.8 (default, Apr 25 2019, 21:02:35) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
[oracle@centos ~]$ su root
パスワード:

[root@centos oracle]# python3 -m ensurepip
Looking in links: /tmp/tmpciyoe1tb
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2


[root@centos oracle]# pip3 install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/62/ca/94d32a6516ed197a491d17d46595ce58a83cbb2fca280414e57cd86b84dc/pip-19.2.1-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 6.9MB/s 
Installing collected packages: pip
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
      Successfully uninstalled pip-18.1
Successfully installed pip-19.2.1

[root@centos oracle]# pip3 list
Package    Version
---------- -------
pip        19.2.1 
setuptools 40.6.2 
[root@centos oracle]# 

[oracle@centos ~]$ pip list
Package    Version
---------- -------
pip        19.2.1 
setuptools 40.6.2 

[oracle@centos ~]$ pip -V
pip 19.2.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
[oracle@centos ~]$ python -V
Python 3.6.8

[oracle@centos ~]$ cat ~/.bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

alias unkommit="/usr/local/bin/unkommit.sh"
alias awk="/usr/local/bin/awk"
alias gawk="/usr/local/bin/awk"
alias python="/usr/bin/python3.6"
alias pip="/usr/local/bin/pip3.6"
alias la="ls -la"
LANG=ja_JP.utf8