スポンサーリンク

【環境構築】Python3.6&pipをインストールしてみた

最近Pythonに興味が出てきたのでvagrantで立ち上げているcentos7にpython3.6を入れてみた

ちなみにcentos7にはデフォルトでpython2.7が入っている

以下確認

[root@localhost ~]# python

Python 2.7.5 (default, Apr 11 2018, 07:36:10)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2

Type “help”, “copyright”, “credits” or “license” for more information.

>>

こちらのページを参考にさせていただき進めた

pythonインストール必要なリポジトリを追加

[root@localhost ~]# yum install -y https://centos7.iuscommunity.org/ius-release.rpm

python3.6があるかどうか検索

[root@localhost ~]# yum search python36

よく使うらしいパッケージをインストール

[root@localhost ~]# yum install -y python36u python36u-libs python36u-devel python36u-pip

インストールされたか確認

[root@localhost ~]# python3.6 -V

Python 3.6.5

Pythonのパッケージ管理システムpipもインストールします

こちらのページを参考にしました

まずはget-pip.pyをダウンロード

それをvagrant環境に置いて以下のようにインストール

[root@localhost vagrant]# ls

get-pip.py git_my_shared

[root@localhost vagrant]# python get-pip.py

Collecting pip

 Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)

   100% |████████████████████████████████| 1.3MB 3.1MB/s

Collecting setuptools

 Downloading https://files.pythonhosted.org/packages/ff/f4/385715ccc461885f3cedf57a41ae3c12b5fec3f35cce4c8706b1a112a133/setuptools-40.0.0-py2.py3-none-any.whl (567kB)

   100% |████████████████████████████████| 573kB 1.5MB/s

Collecting wheel

 Downloading https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl (41kB)

   100% |████████████████████████████████| 51kB 5.8MB/s

Installing collected packages: pip, setuptools, wheel

Successfully installed pip-18.0 setuptools-40.0.0 wheel-0.31.1

[root@localhost vagrant]#

バージョンを確認

[root@localhost vagrant]# pip -V

pip 18.0 from /usr/lib/python2.7/site-packages/pip (python 2.7)

あ、2.7のやつが入ってる・・・

アップデートをしてみるがもう最新だと言われてしまう

[root@localhost vagrant]# pip install -U pip

Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages (18.0)

これは

[root@localhost vagrant]# python get-pip.py

と実行したときにもともとインストールされているpython2.7で実行されたのが原因

[root@localhost vagrant]# python3.6 get-pip.py

と実行すればおk

[root@localhost vagrant]# pip -V

pip 19.0.3 from /usr/lib/python3.6/site-packages/pip (python 3.6)

入ったのを確認

おまけで別のやり方を探してみる

こちらのサイトを参考に

[root@localhost vagrant]# sudo wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

sudo: wget: command not found

wgetないって言われた

こちらのサイトを参考にwgetをインストール

入ってないことを確認

[root@localhost vagrant]# rpm -qa | grep wget

何も出ないので入ってない

[root@localhost vagrant]# yum -y install wget

再び確認

[root@localhost vagrant]# rpm -qa | grep wget

wget-1.14-15.el7_4.1.x86_64

改めてpythonをダウンロード

[root@localhost vagrant]# sudo wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

[root@localhost vagrant]# ls

get-pip.py git_my_shared Python-3.6.1.tgz

解凍します

[root@localhost vagrant]# sudo tar xzvf Python-3.6.1.tgz

[root@localhost vagrant]# ls -la

total 24212

drwxr-xr-x  7 501 games     224 Aug 8 2018.

dr-xr-xr-x. 19 root root      251 Aug 2 20:06..

-rw-r–r–  1 501 games    8196 Aug 7 22:19 .DS_Store

-rw-r–r–  1 501 games 1642522 Aug 7 13:53 get-pip.py

drwxrwxrwx 26 501 games     832 Jul 30 13:26git_my_shared

drwxr-xr-x 29 501 games     928 Mar 21 2017Python-3.6.1

-rw-r–r–  1 501 games 22540566 Mar 21 2017Python-3.6.1.tgz

[root@localhost vagrant]# cd Python-3.6.1/

[root@localhost Python-3.6.1]# sudo ./configure

すると以下のようなエラーが

configure: error: no acceptable C compiler found in $PATH

こちらのページのようにCコンパイラをインストールしないといけないらしい

うぅ・・・めんどい

やめだ

とりあえず解決はしてたのでおわり

コメント

タイトルとURLをコピーしました