메뉴 건너뛰기

XEDITION

OS

linux python 설치

하서기 2016.11.11 11:01 조회 수 : 438

yum install zlib-devel -y
yum install openssl openssl-devel -y


wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz
xz -d Python-3.5.1.tar.xz
# 혹시 xz가 없다면 yum install xz 로 설치 하라.
tar -xvf Python-3.5.1.tar

cd Python-3.5.1
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

# pip설치 
curl -k -O https://bootstrap.pypa.io/get-pip.py
python3.5 get-pip.py

 

==============추가

 

1. IUS Community Project의 리포지토리를 yum의 리포지토리에 추가

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

 

2. Python 3.6을 확인

$ yum search python36

 

$ yum search python35 ← Python 3.5를 확인

 

3. Python 3.6을 설치

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

 

$ python3.6 -V ← 설치 확인

Python 3.6.0

 

$ which python3.6 ← 설치 장소 확인

/usr/bin/python3.6

 

4. Alias 설정

현재 python 커맨드는 2.7로 설정 되어 있음

$ python -V

Python 2.7.5

 

현재 python 커맨드의 Alias를 확인하면 python → python2 → python2.7로 되어 있음

$ ls -l /bin/python*

lrwxrwxrwx  1 root root    12  2月 23 12:04 /bin/python -> /bin/python2

lrwxrwxrwx. 1 root root     9  2月  9 11:39 /bin/python2 -> python2.7

-rwxr-xr-x. 1 root root  7136 11月  6 09:29 /bin/python2.7

lrwxrwxrwx  1 root root    14  2月 23 11:58 /bin/python3 -> /bin/python3.6

-rwxr-xr-x  2 root root 11312  1月 20 08:03 /bin/python3.6

lrwxrwxrwx  1 root root    26  2月 23 11:56 /bin/python3.6-config -> /usr/bin/python3.6m-config

-rwxr-xr-x  2 root root 11312  1月 20 08:03 /bin/python3.6m

-rwxr-xr-x  1 root root   173  1月 20 08:02 /bin/python3.6m-config

-rwxr-xr-x  1 root root  3415  1月 20 07:59 /bin/python3.6m-x86_64-config

 

python → python3 → python3.6으로 설정

$ ln -s /bin/python3.6 /bin/python3

$ unlink /bin/python

$ ln -s /bin/python3 /bin/python

 

pip도 설정

$ ln -s /bin/pip3.6 /bin/pip

 

설정 확인

$ python -V

Python 3.6.0

 

주의점!

Alias를 python3.6으로 설정하면 yum 실행 시 아래와 같은 에러가 발생하므로 yum 사용 시에는 다시 되돌릴 필요가 있음.

혹은 python3 까지만 심볼릭 링크를 걸어서 사용할 것을 권장함.

$ yum

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

   except KeyboardInterrupt, e:

 

$ unlink /bin/python

$ ln -s /bin/python2 /bin/python


 

위로