2. 유닉스 플랫폼에서 파이썬 사용하기
************************************


2.1. 최신 버전의 파이썬 내려받기와 설치
=======================================


2.1.1. 리눅스
-------------

파이썬은 대부분 리눅스 배포판에 사전 설치되어 있으며, 다른 모든 곳에서
패키지로 사용할 수 있습니다. 그러나 배포판 패키지에 없는 어떤 기능을
사용하고 싶을 수 있습니다. 소스에서 최신 버전의 파이썬을 컴파일할 수
있습니다.

최신 버전의 파이썬이 미리 설치되어 있지 않고 저장소에도 없으면, 여러분
자신의 배포를 위한 패키지를 만들 수 있습니다. 다음 링크를 살펴보십시오
:

더 보기:

  https://www.debian.org/doc/manuals/maint-guide/first.en.html
     데비안 사용자용

  https://en.opensuse.org/Portal:Packaging
     OpenSuse 사용자용

  https://docs.fedoraproject.org/en-US/package-
  maintainers/Packaging_Tutorial_GNU_Hello/
     Fedora 사용자용

  https://slackbook.org/html/package-management-making-packages.html
     Slackware 사용자용


2.1.1.1. Installing IDLE
~~~~~~~~~~~~~~~~~~~~~~~~

In some cases, IDLE might not be included in your Python installation.

* 데비안과 우분투 사용자용:

     sudo apt update
     sudo apt install idle

* Fedora, RHEL 및 CentOS 사용자용:

     sudo dnf install python3-idle

* SUSE 와 OpenSuse 사용자용:

     sudo zypper install python3-idle

* 알파인 리눅스 사용자용:

     sudo apk add python3-idle


2.1.2. FreeBSD와 OpenBSD
------------------------

* FreeBSD 사용자, 패키지를 추가하려면 이렇게 하십시오:

     pkg install python3

* OpenBSD 사용자, 패키지를 추가하려면 이렇게 하십시오:

     pkg_add -r python

     pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz

  예를 들어 i386 사용자는 이렇게 파이썬 2.5.1 버전을 얻습니다:

     pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/python-2.5.1p2.tgz


2.2. 파이썬 빌드하기
====================

CPython을 직접 컴파일하려면, 먼저 소스를 얻습니다. 최신 버전의 소스를
내려받거나 새로 clone 할 수 있습니다. (패치에 이바지하려면 clone이 필
요합니다.)

빌드 프로세스는 일반적으로 다음과 같은 명령으로 구성됩니다

   ./configure
   make
   make install

특정 유닉스 플랫폼에 대한 구성 옵션과 주의 사항은 파이썬 소스 트리의
루트에 있는 README.rst 파일에 광범위하게 설명되어있습니다.

경고:

  "make install"은 "python3" 바이너리를 덮어쓰거나 가장 할 수 있습니다
  . 따라서 "make altinstall"을 "make install" 대신 권장하는데,
  "*exec_prefix*/bin/python*version*" 만 설치하기 때문입니다.


2.3. 파이썬 관련 경로와 파일
============================

이는 지역 설치 규칙에 따라 달라질 수 있습니다; "prefix" 와
"exec_prefix"는 설치에 따라 다르며 GNU 소프트웨어처럼 해석되어야 합니
다; 이것들은 같을 수도 있습니다.

예를 들어, 대부분 리눅스 시스템에서, 기본값은 모두 "/usr"입니다.

+-------------------------------------------------+--------------------------------------------+
| 파일/디렉터리                                   | 의미                                       |
|=================================================|============================================|
| "*exec_prefix*/bin/python3"                     | 인터프리터의 권장 위치.                    |
+-------------------------------------------------+--------------------------------------------+
| "*prefix*/lib/python*version*",                 | 표준 모듈을 포함하는 디렉터리의 권장 위치. |
| "*exec_prefix*/lib/python*version*"             |                                            |
+-------------------------------------------------+--------------------------------------------+
| "*prefix*/include/python*version*",             | 파이썬 확장을 개발하고 인터프리터를 내장하 |
| "*exec_prefix*/include/python*version*"         | 는 데 필요한 인클루드 파일을 포함하는 디렉 |
|                                                 | 터리의 권장 위치.                          |
+-------------------------------------------------+--------------------------------------------+


2.4. 잡동사니
=============

유닉스에서 파이썬 스크립트를 쉽게 사용하려면, 실행 파일로 만들어야 합
니다. 예를 들어, 이렇게

   $ chmod +x script

그리고, 스크립트의 상단에 적절한 셔뱅(Shebang) 줄을 넣습니다. 좋은 선
택은 대개 이렇습니다

   #!/usr/bin/env python3

이것은 "PATH" 전체에서 파이썬 인터프리터를 검색합니다. 그러나, 일부 유
닉스에는 **env** 명령이 없을 수 있으므로, 인터프리터 경로로
"/usr/bin/python3"를 하드 코딩해야 할 수 있습니다.

파이썬 스크립트에서 셸 명령을 사용하려면, "subprocess" 모듈을 보십시오
.


2.5. Custom OpenSSL
===================

1. To use your vendor's OpenSSL configuration and system trust store,
   locate the directory with "openssl.cnf" file or symlink in "/etc".
   On most distribution the file is either in "/etc/ssl" or
   "/etc/pki/tls". The directory should also contain a "cert.pem" file
   and/or a "certs" directory.

      $ find /etc/ -name openssl.cnf -printf "%h\n"
      /etc/ssl

2. Download, build, and install OpenSSL. Make sure you use
   "install_sw" and not "install". The "install_sw" target does not
   override "openssl.cnf".

      $ curl -O https://www.openssl.org/source/openssl-VERSION.tar.gz
      $ tar xzf openssl-VERSION
      $ pushd openssl-VERSION
      $ ./config \
          --prefix=/usr/local/custom-openssl \
          --libdir=lib \
          --openssldir=/etc/ssl
      $ make -j1 depend
      $ make -j8
      $ make install_sw
      $ popd

3. Build Python with custom OpenSSL (see the configure "--with-
   openssl" and "--with-openssl-rpath" options)

      $ pushd python-3.x.x
      $ ./configure -C \
          --with-openssl=/usr/local/custom-openssl \
          --with-openssl-rpath=auto \
          --prefix=/usr/local/python-3.x.x
      $ make -j8
      $ make altinstall

참고:

  Patch releases of OpenSSL have a backwards compatible ABI. You don't
  need to recompile Python to update OpenSSL. It's sufficient to
  replace the custom OpenSSL installation with a newer version.
