Python

CentOS 7 파이썬 3.* 설치

Jack Moon 2018. 3. 20. 16:53


python3_install_yum.txt


소스로 설치하는 방법도 있지만 의존성 문제로 make install 과정에서 에러가 나는 경우가 많다.

yum 으로 설치하자.


############# 현재 버전 확인

[root@localhost ~]# python -V

Python 2.7.5


############# Repository 추가

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


############# yum 으로 설치

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


############# 위치확인

[root@localhost bin]# which python3.6

/usr/bin/python3.6

[root@localhost bin]# which pip3.6

/usr/bin/python3.6


기존 python, pip아 겹치지 않게 설정해서 사용



############# link 설정

[root@localhost ~]# ls -l /bin/python*

lrwxrwxrwx. 1 root root     7  3월 20 10:53 /bin/python -> python2

lrwxrwxrwx. 1 root root     9  3월 20 10:53 /bin/python2 -> python2.7

-rwxr-xr-x. 1 root root  7136  8월  4  2017 /bin/python2.7

-rwxr-xr-x. 2 root root 11312 12월 20 05:50 /bin/python3.6

lrwxrwxrwx. 1 root root    26  3월 20 16:15 /bin/python3.6-config -> /usr/bin/python3.6m-config

-rwxr-xr-x. 2 root root 11312 12월 20 05:50 /bin/python3.6m

-rwxr-xr-x. 1 root root   173 12월 20 05:50 /bin/python3.6m-config

-rwxr-xr-x. 1 root root  3435 12월 20 05:48 /bin/python3.6m-x86_64-config


현재 python -> python2 -> python2.7 되어 있는 구조를

변경 python -> python3 -> python3.6 하는 방법이 있지만

문제의 소지를 없애기 위해 python3 -> python3.6 권장


[root@localhost ~]# unlink /bin/python

[root@localhost ~]# ln -s /bin/python3.6 /bin/python3


** python3 으로 할 경우 아래 회색 과정은 생략

[root@localhost ~]# ln -s /bin/python3 /bin/python


이렇게 했을 경우 yum 명령을 치면 다음과 같이 에러가 남. 이유는 yum 명령이 python2 버전을 사용하고 있기 때문

따라서 yum을 수정하면 됨.

[root@localhost ~]# yum update

  File "/usr/bin/yum", line 30

    except KeyboardInterrupt, e:

                            ^

SyntaxError: invalid syntax


[root@localhost ~]# vi /usr/bin/yum

첫째줄

#!/usr/bin/python2 -> #!/usr/bin/python2


############# pip link 설정

[root@localhost ~]# ls -l /bin/pip*

-rwxr-xr-x. 1 root root 370  1월 20  2017 /bin/pip3.6


[root@localhost ~]# ln -s /bin/pip3.6 /bin/pip3


############# 설치 확인

[root@localhost ~]# python3 -V

Python 3.6.4



python3_install_yum.txt
0.0MB