3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

python3 のインストール

3
Last updated at Posted at 2019-06-26

python で画像処理をしてみたい!

とりあえず、インストール。
EC2 のCentOS7系にはpython2系が入っていたので、3系を追加しました。

yumでインストール

rpm をインストール

$ sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm

python3* で見ると、36が最新のため36でインストール

$ yum search python3*

インストール

$ sudo yum install python36u python36u-libs python36u-devel python36u-pip

バージョン確認

$ python -V
Python 2.7.14
$ python3.6 -V
Python 3.6.8

シンボリック・リンクの追加・削除

python コマンドで、3系が動くようにしたい!
まず、現在の状態確認

$ ls -la /usr/bin/python*
lrwxrwxrwx 1 root root     7  3月  9 04:59 /usr/bin/python -> python2
lrwxrwxrwx 1 root root    14  3月  9 04:59 /usr/bin/python-config -> python2-config
lrwxrwxrwx 1 root root     9  3月  9 04:59 /usr/bin/python2 -> python2.7
lrwxrwxrwx 1 root root    16  3月  9 04:59 /usr/bin/python2-config -> python2.7-config
-rwxr-xr-x 1 root root  7048  7月 27  2018 /usr/bin/python2.7
-rwxr-xr-x 1 root root  1846  7月 27  2018 /usr/bin/python2.7-config
-rwxr-xr-x 2 root root 11384  5月  3 05:43 /usr/bin/python3.6
lrwxrwxrwx 1 root root    26  6月 24 22:27 /usr/bin/python3.6-config -> /usr/bin/python3.6m-config
-rwxr-xr-x 2 root root 11384  5月  3 05:43 /usr/bin/python3.6m
-rwxr-xr-x 1 root root   173  5月  3 05:42 /usr/bin/python3.6m-config
-rwxr-xr-x 1 root root  3435  5月  3 05:40 /usr/bin/python3.6m-x86_64-config

[/usr/bin/python -> python2] を3.6に変更する必要がある
シンボリックの削除

$ sudo unlink /usr/bin/python

シンボリックの追加

$ sudo ln -s /usr/bin/python3.6 python

もう一度確認
[python -> /usr/bin/python3.6]に変わっている事を確認

lrwxrwxrwx 1 root root    18  6月 26 11:23 python -> /usr/bin/python3.6
lrwxrwxrwx 1 root root    14  3月  9 04:59 python-config -> python2-config
lrwxrwxrwx 1 root root     9  3月  9 04:59 python2 -> python2.7
lrwxrwxrwx 1 root root    16  3月  9 04:59 python2-config -> python2.7-config
-rwxr-xr-x 1 root root  7048  7月 27  2018 python2.7
-rwxr-xr-x 1 root root  1846  7月 27  2018 python2.7-config
-rwxr-xr-x 2 root root 11384  5月  3 05:43 python3.6
lrwxrwxrwx 1 root root    26  6月 24 22:27 python3.6-config -> /usr/bin/python3.6m-config
-rwxr-xr-x 2 root root 11384  5月  3 05:43 python3.6m
-rwxr-xr-x 1 root root   173  5月  3 05:42 python3.6m-config
-rwxr-xr-x 1 root root  3435  5月  3 05:40 python3.6m-x86_64-config

バージョンの確認

$ python -V
Python 3.6.8

最後に

いろんなサイト参考にさせて頂いたのですが、最後のシンボリックリンクというのを初めてやってドキドキでした。いろんなサイト経由したのですが、ディレクトリが一致せず!!

結果、こちらを参考にシンボリックリンクの設定をしました。感謝。

LPIC勉強すべきかも。


追記

シンボリックを変更したところyumが動かなくなった。
こちらこちらを参考に修正。

[/usr/bin/yum]ファイルの1行目を編集
[#!/usr/bin/python] → [#!/usr/bin/python2.7] へ変更

$ sudo vi /usr/bin/yum
# !/usr/bin/python2.7
import sys
try:
    import yum
except ImportError:
    print >> sys.stderr, """\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   %s

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
%s

If you cannot solve this problem yourself, please go to 
the yum faq at:
  http://yum.baseurl.org/wiki/Faq
  
""" % (sys.exc_value, sys.version)
    sys.exit(1)

sys.path.insert(0, '/usr/share/yum-cli')
try:
    import yummain
    yummain.user_main(sys.argv[1:], exit_code=True)
except KeyboardInterrupt, e:
    print >> sys.stderr, "\n\nExiting on user cancel."
    sys.exit(1)

[/usr/libexec/urlgrabber-ext-down] の1行目
[#! /usr/bin/python] → [#! /usr/bin/python2.7] へ変更

$ sudo vi /usr/libexec/urlgrabber-ext-down
# ! /usr/bin/python2.7

一旦大丈夫かと思いきやダメで、再修正しました。
以上となります。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?