리눅스 Python 2.7 컴파일 설치

Jmnote (토론 | 기여)님의 2014년 2월 7일 (금) 13:43 판
upgrading python to 2.7
파이썬 2.7 업그레이드
파이썬 2.7로 업그레이드
Python 컴파일 설치

1 설치된 버전 확인

[root@jmnote ~]# python -V
Python 2.4.3

2 설치할 버전 확인

  • http://www.python.org/ftp/python/ 접속하여 원하는 버전이 있는지 확인하자.
  • 필자는 2.x 대의 마지막 버전을 추천한다. (여기서는 2.7.6)

3 다운로드 및 설치

명령어
cd /usr/local/src
wget -N http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar xzf Python-2.7.6.tgz
cd Python-2.7.6
./configure
make
make altinstall
실행예시
[root@jmnote ~]# cd /usr/local/src
[root@jmnote src]# wget -N http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
... (생략)
100%[============================================================>] 14,725,931  3.63M/s   in 5.7s    

2014-02-07 13:39:43 (2.47 MB/s) - `Python-2.7.6.tgz` saved [14725931/14725931]
[root@jmnote src]# tar xzf Python-2.7.6.tgz
[root@jmnote src]# cd Python-2.7.6
[root@jmnote Python-2.7.6]# ./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux
... (생략)
creating Modules/Setup
creating Modules/Setup.local
creating Makefile
[root@jmnote Python-2.7.6]# make
gcc -pthread -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes  -I. -IInclude -I./Include   -DPy_BUILD_CORE -o Modules/python.o ./Modules/python.c
gcc -pthread -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes  -I. -IInclude -I./Include   -DPy_BUILD_CORE -o Parser/acceler.o Parser/acceler.c
... (생략)
changing mode of build/scripts-2.7/2to3 from 644 to 755
changing mode of build/scripts-2.7/smtpd.py from 644 to 755
/usr/bin/install -c -m 644 ./Tools/gdb/libpython.py python-gdb.py
[root@jmnote Python-2.7.6]# make altinstall
... (생략)
running install_egg_info
Writing /usr/local/lib/python2.7/lib-dynload/Python-2.7.6-py2.7.egg-info
rm /usr/local/lib/python2.7/lib-dynload/_sysconfigdata.py*

4 바꿔치기

[root@jmnote ~]# ll /usr/bin/python*
-rwxr-xr-x 1 root root    8304 Sep 22  2011 /usr/bin/python
lrwxrwxrwx 1 root root       6 Nov  1  2011 /usr/bin/python2 -> python
-rwxr-xr-x 1 root root    8304 Sep 22  2011 /usr/bin/python2.4
[root@jmnote Python-2.7.6]# cd
[root@jmnote ~]# /usr/bin/python -V
Python 2.4.3
[root@jmnote ~]# /usr/local/bin/python2.7 -V
Python 2.7.6

구버전은 python_old로 이름을 바꾸고 신버전을 python이라는 이름으로 복사한다.

[root@jmnote ~]# mv /usr/bin/python /usr/bin/python_old
[root@jmnote ~]# cp /usr/local/bin/python2.7 /usr/bin/python
[root@jmnote ~]# python -V
Python 2.7.6

5 yum 오류 고치기

python에 의존성이 있던 yum이 제대로 작동하지 않는다...

[root@jmnote ~]# yum
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named yum

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:
2.7.4 (default, Apr 14 2013, 12:44:22) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)]

If you cannot solve this problem yourself, please go to 
the yum faq at:
  http://wiki.linux.duke.edu/YumFaq

다음과 같이 /usr/bin/yum 파일을 수정하자.

[root@jmnote ~]# cp /usr/bin/yum /usr/bin/yum_old
[root@jmnote ~]# sed -i 's/\/usr\/bin\/python/\/usr\/bin\/python2.4/g' /usr/bin/yum
[root@jmnote ~]# diff /usr/bin/yum_old /usr/bin/yum
1c1
< #!/usr/bin/python
---
> #!/usr/bin/python2.4
→ 파일의 1행에 있는 #!/usr/bin/python#!/usr/bin/python2.4로 수정하였다...
[root@jmnote ~]# yum
... (생략)
  --samearch-priorities
                        Priority-exclude packages based on name + arch

  Plugin Options:
→ 이제 잘 된다.

6 같이 보기

7 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}