Service

[Python] Python 설치 (Ubuntu)

dalgong 2025. 2. 6. 08:15
반응형

1. 필수 패키지 설치

$ apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev

2. Python 설치

$ wget <https://www.python.org/ftp/python/3.11.0/Python-3.11.0rc1.tgz>

$ tar -xvf Python-3.11.0rc1.tgz

$ ./configure --enable-optimizations

$ make altinstall

$ python3.11 --version
Python 3.11.0rc1

3. Python 버전 변경

  • Ubuntu에는 기본 Python이 설치되어있다. 필요한 버전을 사용하고 싶으면 버전 변경 작업을 해주어야한다.
$ update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1
(버전 뒤에 띄우고 우선 순위 넣어줘야함)

$ update-alternatives --install /usr/bin/python python /usr/local/bin/python3.11 2
--> 새로 설치한 Python 실행 파일은 /usr/local/bin 에 있음

$ update-alternatives --config python
There are 3 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                           Priority   Status
------------------------------------------------------------
  0            /data/python/Python-3.11.0rc1   2         auto mode
* 1            /data/python/Python-3.11.0rc1   2         manual mode
  2            /usr/bin/python3.12             1         manual mode
  3            /usr/local/bin/python3.11       2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/local/bin/python3.11 to provide /usr/bin/python (python) in manual mode

------> 원하는 버전 선택
  
  $ python --version
Python 3.11.0rc1
반응형