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

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>))
잔글 (봇: Jmnote의 2020-05-27T11:35:08Z 에 작성한 582629 판으로 되돌림)
12번째 줄: 12번째 줄:
[root@zetawiki ~]# python -V
[root@zetawiki ~]# python -V
Python 2.4.3
Python 2.4.3
</syntaxhighlight>
</source>
<source lang='console'>
<source lang='console'>
[root@zetawiki ~]# python -V
[root@zetawiki ~]# python -V
Python 2.6.6
Python 2.6.6
</syntaxhighlight>
</source>


==설치할 버전 확인==
==설치할 버전 확인==
33번째 줄: 33번째 줄:
make
make
make altinstall
make altinstall
</syntaxhighlight>
</source>


{{소스헤더|실행예시}}
{{소스헤더|실행예시}}
44번째 줄: 44번째 줄:


2015-01-21 20:24:50 (10.3 MB/s) - “Python-2.7.9.tgz” saved [16657930/16657930]
2015-01-21 20:24:50 (10.3 MB/s) - “Python-2.7.9.tgz” saved [16657930/16657930]
</syntaxhighlight>
</source>
<source lang='console'>
<source lang='console'>
[root@zetawiki src]# tar xzf Python-$NEW_VER.tgz
[root@zetawiki src]# tar xzf Python-$NEW_VER.tgz
53번째 줄: 53번째 줄:
creating Modules/Setup.local
creating Modules/Setup.local
creating Makefile
creating Makefile
</syntaxhighlight>
</source>
<source lang='console'>
<source lang='console'>
[root@zetawiki Python-2.7.9]# make
[root@zetawiki Python-2.7.9]# make
60번째 줄: 60번째 줄:
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
</syntaxhighlight>
</source>
<source lang='console'>
<source lang='console'>
[root@zetawiki Python-2.7.9]# make altinstall
[root@zetawiki Python-2.7.9]# make altinstall
76번째 줄: 76번째 줄:
$ensurepip --root=/ ; \
$ensurepip --root=/ ; \
fi
fi
</syntaxhighlight>
</source>


==바꿔치기==
==바꿔치기==
88번째 줄: 88번째 줄:
lrwxrwxrwx  1 root root  16 Sep  4 02:35 /usr/bin/python-config -> 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
lrwxrwxrwx  1 root root    3 Sep  4 02:23 /usr/bin/python-pip -> pip
</syntaxhighlight>
</source>
<source lang='console'>
<source lang='console'>
[root@zetawiki ~]# python -V
[root@zetawiki ~]# python -V
96번째 줄: 96번째 줄:
[root@zetawiki ~]# /usr/local/bin/python2.7 -V
[root@zetawiki ~]# /usr/local/bin/python2.7 -V
Python 2.7.9
Python 2.7.9
</syntaxhighlight>
</source>
구버전은 python_old로 이름을 바꾸고 신버전을 python이라는 이름으로 복사한다.
구버전은 python_old로 이름을 바꾸고 신버전을 python이라는 이름으로 복사한다.
<source lang='console'>
<source lang='console'>
103번째 줄: 103번째 줄:
[root@zetawiki ~]# python -V
[root@zetawiki ~]# python -V
Python 2.7.9
Python 2.7.9
</syntaxhighlight>
</source>


==(필요시) yum 오류 고치기==
==(필요시) yum 오류 고치기==
126번째 줄: 126번째 줄:
the yum faq at:
the yum faq at:
   http://yum.baseurl.org/wiki/Faq
   http://yum.baseurl.org/wiki/Faq
</syntaxhighlight>
</source>
다음과 같이 /usr/bin/yum 파일을 수정하자.
다음과 같이 /usr/bin/yum 파일을 수정하자.
:기존 버전이 2.4이였다면  <code>#!/usr/bin/python</code> → <code>#!/usr/bin/python2.4</code>
:기존 버전이 2.4이였다면  <code>#!/usr/bin/python</code> → <code>#!/usr/bin/python2.4</code>
138번째 줄: 138번째 줄:
---
---
> #!/usr/bin/python2.6
> #!/usr/bin/python2.6
</syntaxhighlight>
</source>
<source lang='console'>
<source lang='console'>
[root@zetawiki ~]# yum
[root@zetawiki ~]# yum
146번째 줄: 146번째 줄:
     --advisory=ADVISORY
     --advisory=ADVISORY
                         Include packages needed to fix the given advisory
                         Include packages needed to fix the given advisory
</syntaxhighlight>
</source>
:→ 이제 잘 된다.
:→ 이제 잘 된다.


169번째 줄: 169번째 줄:
Installed size: 78 k
Installed size: 78 k
Is this ok [y/N]: y
Is this ok [y/N]: y
</syntaxhighlight>
</source>
<source lang='console'>
<source lang='console'>
... (생략)
... (생략)
176번째 줄: 176번째 줄:


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


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 00:52 판

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 }}