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

잔글 (Jmnote 사용자가 리눅스 Python 2.7 업그레이드 문서를 리눅스 Python 2.7 컴파일 설치 문서로 옮겼습니다)
 
(사용자 3명의 중간 판 47개는 보이지 않습니다)
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.4로 업그레이드
;파이썬 2.7로 업그레이드
;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.4를 추천한다.
:이 문서에서는 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.4/Python-2.7.4.tgz
wget --no-check-certificate -N http://www.python.org/ftp/python/$NEW_VER/Python-$NEW_VER.tgz  
tar xzf Python-2.7.tgz
tar xzf Python-$NEW_VER.tgz
cd Python-2.7
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.4/Python-2.7.4.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,489,063 2.43M/s  in 9.5s
100%[===================================================>] 16,657,930 10.3M/s  in 1.5s  


2013-04-14 12:39:56 (1.46 MB/s) - `Python-2.7.4.tgz.1' saved [14489063/14489063]
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.4.tgz
[root@zetawiki src]# tar xzf Python-$NEW_VER.tgz
[root@jmnote src]# cd Python-2.7.4
[root@zetawiki src]# cd Python-$NEW_VER
[root@jmnote Python-2.7.4]# ./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.4]# 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
... (생략)
... (생략)
creating build/scripts-2.7
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.4]# make altinstall
[root@zetawiki Python-2.7.9]# make altinstall
... (생략)
... (생략)
changing mode of /usr/local/bin/pydoc to 755
Writing /usr/local/lib/python2.7/lib-dynload/Python-2.7.9-py2.7.egg-info
running install_egg_info
rm /usr/local/lib/python2.7/lib-dynload/_sysconfigdata.py*
Writing /usr/local/lib/python2.7/lib-dynload/Python-2.7.4-py2.7.egg-info
/usr/bin/install -c -m 644 ./Misc/python.man \
</source>
/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.4]# 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.4
[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.4
Python 2.7.9
</source>
</syntaxhighlight>


==yum 오류 고치기==
==(필요시) yum 오류 고치기==
python에 의존성이 있던 yum이 제대로 작동하지 않는다...
{{참고|No module named yum}}
<source lang='dos'>
yum이 제대로 작동하지 않는다…<ref>[[/usr/bin/yum]]도 파이썬 스크립트임</ref>
[root@jmnote ~]# yum
<syntaxhighlight lang='console'>
[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:
101번째 줄: 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
                        Include packages needed to fix the given advisory
</syntaxhighlight>
:→ 이제 잘 된다.


   Plugin Options:
==(필요시) 원상복구==
</source>
*예전 버전으로 되돌리고 싶다면 yum에 있는 python으로 재설치하자.
:→ 이제 잘 된다.
*사실 원상복구는 아니다...
:기존과 완전히 동일한 버전은 아니지만 yum이 의존성을 잘 맞춰줘서 별 문제 없을 것이다.
<syntaxhighlight lang='console'>
[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
</syntaxhighlight>
<syntaxhighlight lang='console'>
... (생략)
Installed:
   python.x86_64 0:2.6.6-52.el6                                                                       
 
Complete!
</syntaxhighlight>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# python -V
Python 2.6.6
</syntaxhighlight>


==같이 보기==
==같이 보기==
135번째 줄: 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 }}