또이리의 Server Engineer

Python 3 install - 우분투 파이썬 3 설치 본문

Linux Engineer

Python 3 install - 우분투 파이썬 3 설치

또이리 2020. 11. 14. 23:07

Python 3 install - 우분투 파이썬 3 설치

ubuntu 18.04 Python install 이번 스토리는 파이썬 설치하는 방법입니다.

우선 파이썬은 프로그래밍 언어입니다.

 

세계적으로 널리 사용되는 프로그래밍 언어로 간단하고 배우기 쉬운 구문으로 초보 개발자와 고급 개발자 사이에서 인기가 높습니다.

 

독립적인 플랫폼으로 대화형 언어입니다. 개발자들에 따라서 파이썬 2 버전을 사용하기도, 파이썬 3 버전을 사용하기도 합니다.

 

Python install

파이썬을 설치하는 법을 알아보겠습니다.

우분투에는 기본적으로 파이썬이 설치되어있습니다.

root@localhost:~# whereis python
python: /usr/bin/python3.6m /usr/bin/python3.6 /usr/lib/python3.7 /usr/lib/python2.7 /usr/lib/python3.8 /usr/lib/python3.6 /etc/python3.6 /usr/local/lib/python3.6 /usr/share/python
root@localhost:~# python

Command 'python' not found, but can be installed with:

apt install python3
apt install python
apt install python-minimal

You also have python3 installed, you can run 'python3' instead.

root@localhost:~# python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

우선 whereis 명령어로 python이 설치된 폴더의 위치를 알 수 있습니다.

/usr/bin 디렉터리 안에 있는 버전을 사용할 수 있습니다.

python 명령어를 입력했을 때 기본적으로 파이썬의 2 버전으로 실행됩니다.

 

이 시스템은 파이썬 3.6 버전이 설치되어 있는 것이 보입니다.

그렇다면 python3을 입력해봅니다.

python3.6.9 버전이 실행되었습니다.

 

저는 파이썬 3.8을 설치해 보겠습니다. 현재 2020-11-14 기준으로 python3는 3.9.0까지 버전이 업데이트되어있습니다. 지금 제가 스토리에 사용하는 우분투는 18.04.4 버전입니다.

 

이 우분투 버전에서는 기본 레포지터리로 apt-get install python3라고 인스톨을 실행해도 python3.6.9 버전 이상으로 업데이트되지 않습니다.

 

이제 레포지터리를 추가해서 python3.8을 설치해 보겠습니다.

 

항상 말씀드리지만 내부 네트워크가 아닌 외부 네트워크망을 사용할 수 있는 환경이 된다면, 레포지터리 추가로 설치하시는 게 제일 깔끔하며 의존성 파일들을 신경 쓰지 않아도 됩니다.

 

자동으로 필요한 파일과 패키지를 설치해주기 때문입니다. 외부망이란 쉽게 말하면 인터넷이 되냐 안되냐는 것입니다.

 

당연히 설치를 진행할 때는 관리자 권한이 있어야겠습니다.

sudo 권한이 있어야 apt 관리자를 사용할 수 있습니다.

 

우선 습관적인 명령어입니다.

apt-get update 패키지 목록을 최신으로 업데이트시켜줍니다.

 

그다음은 레포지터리를 추가할 수 있는 패키지를 설치해줍니다.

apt-get install software-properties-commom 해당 패키지가 설치되었다면,

apt-add-repository를 사용할 수 있습니다.

 

요즘은 apt-get 대신 apt를 많이 사용하시는데 apt가 좀 더 세련됐다고 생각하시면 될 것 같습니다. 아직까지는 크게 차이는 없는 것 같습니다.

 

파이썬 3의 레포지터리를 추가합니다.

apt-add-repository ppa:deadsnakes/ppa

root@localhost:/usr/bin# apt-get install software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  python3-software-properties
The following packages will be upgraded:
  python3-software-properties software-properties-common
2 upgraded, 0 newly installed, 0 to remove and 165 not upgraded.
Need to get 33.9 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 software-properties-common all 0.96.24.32.14 [10.1 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-software-properties all 0.96.24.32.14 [23.9 kB]
Fetched 33.9 kB in 1s (25.9 kB/s)
(Reading database ... 68378 files and directories currently installed.)
Preparing to unpack .../software-properties-common_0.96.24.32.14_all.deb ...
Unpacking software-properties-common (0.96.24.32.14) over (0.96.24.32.12) ...
Preparing to unpack .../python3-software-properties_0.96.24.32.14_all.deb ...
Unpacking python3-software-properties (0.96.24.32.14) over (0.96.24.32.12) ...
Setting up python3-software-properties (0.96.24.32.14) ...
Setting up software-properties-common (0.96.24.32.14) ...
Processing triggers for dbus (1.12.2-1ubuntu1.1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

root@localhost:/usr/bin# apt-add-repository ppa:deadsnakes/ppa

엔터로 진행 또는 Ctrl-c로 취소라는 메시지가 출력되면 엔터로 진행합니다.

그다음 명령어 프롬프트가 활성화되면, 당연히 등록한 레포지터리 목록을 업데이트해야겠습니다.

 

apt-get update 명령어를 사용합니다.

모든 게 정상적으로 진행되었다면, 이제 파이썬 3.8을 설치할 수 있습니다.

apt-get install python3.8 설치를 진행합니다.

root@localhost:/usr/bin# apt-get install python3.8
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libpython3.8-minimal libpython3.8-stdlib python3.8-minimal
Suggested packages:
  python3.8-venv python3.8-doc binutils binfmt-support
The following NEW packages will be installed:
  libpython3.8-minimal libpython3.8-stdlib python3.8 python3.8-minimal
0 upgraded, 4 newly installed, 0 to remove and 165 not upgraded.
Need to get 4,551 kB of archives.
After this operation, 18.5 MB of additional disk space will be used.
Do you want to continue? [Y/n]

y를 눌러서 진행해 줍니다. -y 옵션을 명령어 줄에 추가해서 자동으로 y를 선택할 수도 있습니다.

apt-get install -y python3.8 이렇게 사용하면 됩니다.

 

이제 설치가 완료되었으면 버전을 확인해 보겠습니다.

root@localhost:/usr/bin# python3 --version
Python 3.6.9
root@localhost:/usr/bin# python3.8 --version
Python 3.8.0
root@localhost:/usr/bin# python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[10]+  Stopped                 python3
root@localhost:/usr/bin# python3.8
Python 3.8.0 (default, Oct 28 2019, 16:14:01)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[11]+  Stopped                 python3.8
root@localhost:/usr/bin# whereis python
python: /usr/bin/python3.8 /usr/bin/python3.6m /usr/bin/python3.6 /usr/lib/python3.7 /usr/lib/python2.7 /usr/lib/python3.8 /usr/lib/python3.6 /etc/python3.8 /etc/python3.6 /usr/local/lib/python3.8 /usr/local/lib/python3.6 /usr/share/python
root@localhost:/usr/bin#

--version 옵션으로 기본 python3의 버전과 추가로 설치된 python3.8의 버전을 확인했습니다.

그리고 실행도 시켜보았습니다. 빠져나오실 때는 Ctrl+z키 사용하시면 됩니다.

 

whereis python으로 위치를 확인했을 때

/usr/bin/python3.8이 추가된 것이 확인됩니다.

 

이제 python 3.8을 사용할 수 있습니다.

python 3.8

Comments