"리눅스 Python 2.7 컴파일 설치"의 두 판 사이의 차이

 
(사용자 3명의 중간 판 34개는 보이지 않습니다)
1번째 줄: 1번째 줄:
{{테스트|CentOS 5 + Python 2.4( → Python 2.7 )}}
{{테스트|CentOS 6 + Python 2.6( → Python 2.7 )}}
;upgrading python to 2.7
;upgrading python to 2.7
;파이썬 2.7 업그레이드
;파이썬 2.7 업그레이드
;파이썬 2.7로 업그레이드
;파이썬 2.7로 업그레이드
;Python 컴파일 설치
;Python 컴파일 설치
* 참고로 CentOS 7에는 Python 2.7이 기본 설치되어 있다. → [[CentOS 7 최소설치 패키지 목록]]


==설치된 버전 확인==
==설치된 버전 확인==
{{참고|파이썬 버전 확인}}
{{참고|파이썬 버전 확인}}
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# python -V
[root@zetawiki ~]# python -V
Python 2.4.3
Python 2.4.3
</source>
</syntaxhighlight>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# python -V
Python 2.6.6
</syntaxhighlight>


==설치할 버전 확인==
==설치할 버전 확인==
*http://www.python.org/ftp/python/ 접속하여 원하는 버전이 있는지 확인하자.
*http://www.python.org/ftp/python/ 접속하여 원하는 버전이 있는지 확인하자.
*필자는 2.x 대의 마지막 버전을 추천한다. (여기서는 2.7.6)
:이 문서에서는 2.7.9로 실습


==다운로드 및 설치==
==다운로드 및 설치==
;명령어
{{소스헤더|명령어}}
<source lang='bash'>
<syntaxhighlight lang='bash'>
NEW_VER=2.7.9
cd /usr/local/src
cd /usr/local/src
wget -N http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
wget --no-check-certificate -N http://www.python.org/ftp/python/$NEW_VER/Python-$NEW_VER.tgz  
tar xzf Python-2.7.6.tgz
tar xzf Python-$NEW_VER.tgz
cd Python-2.7.6
cd Python-$NEW_VER
./configure
./configure
make
make
make altinstall
make altinstall
</source>
</syntaxhighlight>


;실행예시
{{소스헤더|실행예시}}
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# cd /usr/local/src
[root@zetawiki ~]# NEW_VER=2.7.9
[root@jmnote src]# wget -N http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
[root@zetawiki ~]# cd /usr/local/src
[root@zetawiki src]# wget --no-check-certificate -N http://www.python.org/ftp/python/$NEW_VER/Python-$NEW_VER.tgz
... (생략)
... (생략)
100%[============================================================>] 14,725,931 3.63M/s  in 5.7s    
100%[===================================================>] 16,657,930 10.3M/s  in 1.5s    


2014-02-07 13:39:43 (2.47 MB/s) - `Python-2.7.6.tgz` saved [14725931/14725931]
2015-01-21 20:24:50 (10.3 MB/s) - “Python-2.7.9.tgz” saved [16657930/16657930]
</source>
</syntaxhighlight>
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote src]# tar xzf Python-2.7.6.tgz
[root@zetawiki src]# tar xzf Python-$NEW_VER.tgz
[root@jmnote src]# cd Python-2.7.6
[root@zetawiki src]# cd Python-$NEW_VER
[root@jmnote Python-2.7.6]# ./configure
[root@zetawiki Python-2.7.9]# ./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux
... (생략)
... (생략)
creating Modules/Setup
creating Modules/Setup
creating Modules/Setup.local
creating Modules/Setup.local
creating Makefile
creating Makefile
</source>
</syntaxhighlight>
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote Python-2.7.6]# make
[root@zetawiki Python-2.7.9]# 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/2to3 from 644 to 755
changing mode of build/scripts-2.7/smtpd.py 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
/usr/bin/install -c -m 644 ./Tools/gdb/libpython.py python-gdb.py
</source>
</syntaxhighlight>
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote Python-2.7.6]# make altinstall
[root@zetawiki Python-2.7.9]# make altinstall
... (생략)
... (생략)
running install_egg_info
Writing /usr/local/lib/python2.7/lib-dynload/Python-2.7.9-py2.7.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*
rm /usr/local/lib/python2.7/lib-dynload/_sysconfigdata.py*
</source>
/usr/bin/install -c -m 644 ./Misc/python.man \
/usr/local/share/man/man1/python2.7.1
if test "xno" != "xno"  ; then \
case no in \
upgrade) ensurepip="--altinstall --upgrade --no-default-pip" ;; \
install|*) ensurepip="--altinstall --no-default-pip" ;; \
esac; \
./python -E -m ensurepip \
$ensurepip --root=/ ; \
fi
</syntaxhighlight>


==바꿔치기==
==바꿔치기==
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# ll /usr/bin/python*
[root@zetawiki Python-2.7.9]# cd
-rwxr-xr-x 1 root root   8304 Sep 22  2011 /usr/bin/python
[root@zetawiki ~]# ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       6 Nov  1 2011 /usr/bin/python2 -> python
-rwx------. 2 root root 9032 Jan 22  2014 /usr/bin/python
-rwxr-xr-x 1 root root   8304 Sep 22 2011 /usr/bin/python2.4
lrwxrwxrwx. 1 root root   6 May 26 2014 /usr/bin/python2 -> python
</source>
-rwx------. 2 root root 9032 Jan 22  2014 /usr/bin/python2.6
<source lang='dos'>
-rwxr-xr-x 1 root root 1418 Jan 22  2014 /usr/bin/python2.6-config
[root@jmnote Python-2.7.6]# cd
lrwxrwxrwx  1 root root  16 Sep  4 02:35 /usr/bin/python-config -> python2.6-config
[root@jmnote ~]# /usr/bin/python -V
lrwxrwxrwx  1 root root    3 Sep  4 02:23 /usr/bin/python-pip -> pip
Python 2.4.3
</syntaxhighlight>
</source>
<syntaxhighlight lang='console'>
<source lang='dos'>
[root@zetawiki ~]# python -V
[root@jmnote ~]# /usr/local/bin/python2.7 -V
Python 2.6.6
Python 2.7.6
[root@zetawiki ~]# /usr/bin/python -V
</source>
Python 2.6.6
[root@zetawiki ~]# /usr/local/bin/python2.7 -V
Python 2.7.9
</syntaxhighlight>
구버전은 python_old로 이름을 바꾸고 신버전을 python이라는 이름으로 복사한다.
구버전은 python_old로 이름을 바꾸고 신버전을 python이라는 이름으로 복사한다.
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# mv /usr/bin/python /usr/bin/python_old
[root@zetawiki ~]# mv /usr/bin/python /usr/bin/python_old
[root@jmnote ~]# cp /usr/local/bin/python2.7 /usr/bin/python
[root@zetawiki ~]# cp /usr/local/bin/python2.7 /usr/bin/python
[root@jmnote ~]# python -V
[root@zetawiki ~]# python -V
Python 2.7.6
Python 2.7.9
</source>
</syntaxhighlight>


==(옵션) yum 오류 고치기==
==(필요시) yum 오류 고치기==
{{참고|No module named yum}}
yum이 제대로 작동하지 않는다…<ref>[[/usr/bin/yum]]도 파이썬 스크립트임</ref>
yum이 제대로 작동하지 않는다…<ref>[[/usr/bin/yum]]도 파이썬 스크립트임</ref>
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# yum
[root@zetawiki ~]# yum
There was a problem importing one of the Python modules
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
required to run yum. The error leading to this problem was:
102번째 줄: 120번째 줄:
It's possible that the above module doesn't match the
It's possible that the above module doesn't match the
current version of Python, which is:
current version of Python, which is:
2.7.4 (default, Apr 14 2013, 12:44:22)  
2.7.9 (default, Jan 21 2015, 20:29:09)  
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)]
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)]


If you cannot solve this problem yourself, please go to  
If you cannot solve this problem yourself, please go to  
the yum faq at:
the yum faq at:
   http://wiki.linux.duke.edu/YumFaq
   http://yum.baseurl.org/wiki/Faq
</source>
</syntaxhighlight>
다음과 같이 /usr/bin/yum 파일을 수정하자.  
다음과 같이 /usr/bin/yum 파일을 수정하자.
<source lang='dos'>
:기존 버전이 2.4이였다면  <code>#!/usr/bin/python</code> → <code>#!/usr/bin/python2.4</code>
[root@jmnote ~]# cp /usr/bin/yum /usr/bin/yum_old
:기존 버전이 2.6이였다면  <code>#!/usr/bin/python</code> → <code>#!/usr/bin/python2.6</code>
[root@jmnote ~]# sed -i 's/\/usr\/bin\/python/\/usr\/bin\/python2.4/g' /usr/bin/yum
<syntaxhighlight lang='console'>
[root@jmnote ~]# diff /usr/bin/yum_old /usr/bin/yum
[root@zetawiki ~]# cp /usr/bin/yum /usr/bin/yum_old
[root@zetawiki ~]# sed -i 's/\/usr\/bin\/python/\/usr\/bin\/python2.6/g' /usr/bin/yum
[root@zetawiki ~]# diff /usr/bin/yum_old /usr/bin/yum
1c1
1c1
< #!/usr/bin/python
< #!/usr/bin/python
---
---
> #!/usr/bin/python2.4
> #!/usr/bin/python2.6
</source>
</syntaxhighlight>
:→ 파일의 1행에 있는 <code>#!/usr/bin/python</code>을 <code>#!/usr/bin/python2.4</code>로 수정하였다...
<syntaxhighlight lang='console'>
<source lang='dos'>
[root@zetawiki ~]# yum
[root@jmnote ~]# yum
... (생략)
... (생략)
  --samearch-priorities
    --sec-severity=SEVERITY
                         Priority-exclude packages based on name + arch
                         Include security relevant packages, of this severity
 
    --advisory=ADVISORY
  Plugin Options:
                        Include packages needed to fix the given advisory
</source>
</syntaxhighlight>
:→ 이제 잘 된다.
:→ 이제 잘 된다.


==(원상복구)==
==(필요시) 원상복구==
예전 버전으로 되돌리고 싶다면 yum에 있는 python으로 재설치하면 된다.
*예전 버전으로 되돌리고 싶다면 yum에 있는 python으로 재설치하자.
<source lang='dos'>
*사실 원상복구는 아니다...
[root@jmnote ~]# yum reinstall python
:기존과 완전히 동일한 버전은 아니지만 yum이 의존성을 잘 맞춰줘서 별 문제 없을 것이다.
<syntaxhighlight lang='console'>
[root@zetawiki ~]# yum reinstall python
... (생략)
... (생략)
======================================================================================================
======================================================================================================
148번째 줄: 169번째 줄:
Installed size: 78 k
Installed size: 78 k
Is this ok [y/N]: y
Is this ok [y/N]: y
</source>
</syntaxhighlight>
<source lang='dos'>
<syntaxhighlight lang='console'>
... (생략)
... (생략)
Installed:
Installed:
155번째 줄: 176번째 줄:


Complete!
Complete!
</source>
</syntaxhighlight>
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# python -V
[root@zetawiki ~]# python -V
Python 2.6.6
Python 2.6.6
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
167번째 줄: 188번째 줄:
*[[리눅스 Python 2.6 설치]]
*[[리눅스 Python 2.6 설치]]


==참고 자료==
==주석==
<references/>
 
==참고==
*http://speedpointer.blogspot.kr/2011/07/ubuntu-27.html
*http://speedpointer.blogspot.kr/2011/07/ubuntu-27.html
*http://serverfault.com/questions/344127/installing-python-2-7-broke-yum
*http://serverfault.com/questions/344127/installing-python-2-7-broke-yum
*https://www.scaler.com/topics/python/how-to-install-python-in-windows/


[[분류: python]]
[[분류: python]]
[[분류: 컴파일 설치]]
[[분류: 컴파일 설치]]

2022년 11월 14일 (월) 02:12 기준 최신판

upgrading python to 2.7
파이썬 2.7 업그레이드
파이썬 2.7로 업그레이드
Python 컴파일 설치

1 설치된 버전 확인[ | ]

[root@zetawiki ~]# python -V
Python 2.4.3
[root@zetawiki ~]# python -V
Python 2.6.6

2 설치할 버전 확인[ | ]

이 문서에서는 2.7.9로 실습

3 다운로드 및 설치[ | ]

명령어
NEW_VER=2.7.9
cd /usr/local/src
wget --no-check-certificate -N http://www.python.org/ftp/python/$NEW_VER/Python-$NEW_VER.tgz 
tar xzf Python-$NEW_VER.tgz
cd Python-$NEW_VER
./configure
make
make altinstall
실행예시
[root@zetawiki ~]# NEW_VER=2.7.9
[root@zetawiki ~]# cd /usr/local/src
[root@zetawiki src]# wget --no-check-certificate -N http://www.python.org/ftp/python/$NEW_VER/Python-$NEW_VER.tgz
... (생략)
100%[===================================================>] 16,657,930  10.3M/s   in 1.5s    

2015-01-21 20:24:50 (10.3 MB/s) - “Python-2.7.9.tgz” saved [16657930/16657930]
[root@zetawiki src]# tar xzf Python-$NEW_VER.tgz
[root@zetawiki src]# cd Python-$NEW_VER
[root@zetawiki Python-2.7.9]# ./configure
... (생략)
creating Modules/Setup
creating Modules/Setup.local
creating Makefile
[root@zetawiki Python-2.7.9]# make
... (생략)
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@zetawiki Python-2.7.9]# make altinstall
... (생략)
Writing /usr/local/lib/python2.7/lib-dynload/Python-2.7.9-py2.7.egg-info
rm /usr/local/lib/python2.7/lib-dynload/_sysconfigdata.py*
/usr/bin/install -c -m 644 ./Misc/python.man \
		/usr/local/share/man/man1/python2.7.1
if test "xno" != "xno"  ; then \
		case no in \
			upgrade) ensurepip="--altinstall --upgrade --no-default-pip" ;; \
			install|*) ensurepip="--altinstall --no-default-pip" ;; \
		esac; \
		 ./python -E -m ensurepip \
			$ensurepip --root=/ ; \
	fi

4 바꿔치기[ | ]

[root@zetawiki Python-2.7.9]# cd
[root@zetawiki ~]# ls -l /usr/bin/python*
-rwx------. 2 root root 9032 Jan 22  2014 /usr/bin/python
lrwxrwxrwx. 1 root root    6 May 26  2014 /usr/bin/python2 -> python
-rwx------. 2 root root 9032 Jan 22  2014 /usr/bin/python2.6
-rwxr-xr-x  1 root root 1418 Jan 22  2014 /usr/bin/python2.6-config
lrwxrwxrwx  1 root root   16 Sep  4 02:35 /usr/bin/python-config -> python2.6-config
lrwxrwxrwx  1 root root    3 Sep  4 02:23 /usr/bin/python-pip -> pip
[root@zetawiki ~]# python -V
Python 2.6.6
[root@zetawiki ~]# /usr/bin/python -V
Python 2.6.6
[root@zetawiki ~]# /usr/local/bin/python2.7 -V
Python 2.7.9

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

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

5 (필요시) yum 오류 고치기[ | ]

yum이 제대로 작동하지 않는다…[1]

[root@zetawiki ~]# 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.9 (default, Jan 21 2015, 20:29:09) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)]

If you cannot solve this problem yourself, please go to 
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

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

기존 버전이 2.4이였다면 #!/usr/bin/python#!/usr/bin/python2.4
기존 버전이 2.6이였다면 #!/usr/bin/python#!/usr/bin/python2.6
[root@zetawiki ~]# cp /usr/bin/yum /usr/bin/yum_old
[root@zetawiki ~]# sed -i 's/\/usr\/bin\/python/\/usr\/bin\/python2.6/g' /usr/bin/yum
[root@zetawiki ~]# diff /usr/bin/yum_old /usr/bin/yum
1c1
< #!/usr/bin/python
---
> #!/usr/bin/python2.6
[root@zetawiki ~]# yum
... (생략)
    --sec-severity=SEVERITY
                        Include security relevant packages, of this severity
    --advisory=ADVISORY
                        Include packages needed to fix the given advisory
→ 이제 잘 된다.

6 (필요시) 원상복구[ | ]

  • 예전 버전으로 되돌리고 싶다면 yum에 있는 python으로 재설치하자.
  • 사실 원상복구는 아니다...
기존과 완전히 동일한 버전은 아니지만 yum이 의존성을 잘 맞춰줘서 별 문제 없을 것이다.
[root@zetawiki ~]# yum reinstall python
... (생략)
======================================================================================================
 Package               Arch                  Version                     Repository              Size
======================================================================================================
Reinstalling:
 python                x86_64                2.6.6-52.el6                updates                 74 k

Transaction Summary
======================================================================================================
Reinstall     1 Package(s)

Total download size: 74 k
Installed size: 78 k
Is this ok [y/N]: y
... (생략)
Installed:
  python.x86_64 0:2.6.6-52.el6                                                                        

Complete!
[root@zetawiki ~]# python -V
Python 2.6.6

7 같이 보기[ | ]

8 주석[ | ]

  1. /usr/bin/yum도 파이썬 스크립트임

9 참고[ | ]

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