RHEL/CentOS ์— python 2.7, 3.* ์„ค์น˜ํ•˜๊ธฐ

ย 

ย 

๊ฐœ์š”

CentOS 6 ์—๋Š” Python 2.6 ์ด ํƒ‘์žฌ๋˜์–ด ์žˆ์œผ๋ฉฐ ๋งŽ์€ ์‹œ์Šคํ…œ ์œ ํ‹ธ๋ฆฌํ‹ฐ(Ex: semange ๊ฐ™์€ SELinux ๊ด€๋ฆฌ ์œ ํ‹ธ)์ด ๊ธฐ๋ณธ ์„ค์น˜๋œ ํŒŒ์ด์ฌ๊ณผ ์˜์กด ๊ด€๊ณ„์— ์žˆ์Šต๋‹ˆ๋‹ค.

ย 

python ์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ๋กœ๊ทธ ์ทจํ•ฉ ์„œ๋น„์Šค์ธ Sentry ๋Š” Python 2.7 ์ด์ƒ์„ ์š”๊ตฌํ•˜๋ฉฐ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์„ค์น˜ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

ย 

  1. ์†Œ์Šค tarball ์„ ๋‹ค์šด ๋ฐ›์•„์„œ ์ปดํŒŒ์ผํ•˜์—ฌ ์„ค์น˜
  2. rpm ํŒจํ‚ค์ง€๋ฅผ ๊ตฌํ•ด์„œ ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €๋กœ ์„ค์น˜

ย 

๊ฐœ์ธ์ ์œผ๋กœ๋Š” ์›ฌ๋งŒํ•˜๋ฉด ์†Œ์Šค ์ปดํŒŒ์ผ์„ ์ž์ œํ•˜๋Š” ํŽธ์ด์ง€๋งŒ python ์€ CentOS ์— ๊ผญ ํ•„์š”ํ•œ ํ”„๋กœ๊ทธ๋žจ์ด๋ฉฐ 2๋ฒˆ ๋ฐฉ์‹์œผ๋กœ ์„ค์น˜ํ•  ๊ฒฝ์šฐ ๊ธฐ๋ณธ ์„ค์น˜๋œ python ์— ๋ฎ์–ด์จ์„œย ์‹œ์Šคํ…œ ์œ ํ‹ธ๋ฆฌํ‹ฐ๊ฐ€ ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š์„ ์œ„ํ—˜์ด ์žˆ์Šต๋‹ˆ๋‹ค.

ย 

๊ทธ๋ž˜์„œย 1๋ฒˆ ๋ฐฉ์‹์œผ๋กœ ์†Œ์Šค๋ฅผ ๋‹ค์šด๋ฐ›์•„์„œ ์„ค์น˜ํ•˜๋Š” ๊ฒŒ ๋‚ซ๋‹ค๊ณ  ํŒ๋‹จํ•˜์˜€๊ณ  ๊ธฐ์กด python ๊ณผ ์ค‘๋ณต๋˜์ง€ ์•Š๊ฒŒ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์น˜ ํ–ˆ์Šต๋‹ˆ๋‹ค.

ย 

์„ค์น˜

  1. https://www.python.org/downloads/ ย ์—์„œ ๋‹ค์šด๋กœ๋“œ

    python2
    wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz
    python3
    wget https://www.python.org/ftp/python/3.4.6/Python-3.4.6.tar.xz
  2. ์••์ถ• ํ•ด์ œ

    tar xJvf Python-2.7.12.tar.xz
    python3
    tar xJvf Python-3.4.6.tar.xz
  3. ํด๋”๋กœ ์ด๋™

    cd Python-2.7.12
    python3
    cd Python-3.4.6
  4. auto config ์ˆ˜ํ–‰. ์ด๋•Œ ์ค‘์š”ํ•œ ๊ฒƒ์€ --prefix ์˜ต์…˜์œผ๋กœ ์„ค์น˜๋  ๊ฒฝ๋กœ๋ฅผ ์ง€์ •ํ•ด ์ฃผ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    ./configure --prefix=/usr/local/python2.7 --enable-shared
    python3
    ./configure --prefix=/usr/local/python3.4 --enable-shared
  5. make ๋กœ ์ปดํŒŒ์ผํ•˜๊ณ  test ๋กœ ํ•œ ๋ฒˆ ๋Œ๋ ค์ค๋‹ˆ๋‹ค.

    make test
  6. ์ •์ƒ์ ์œผ๋กœ ๋๋‚ฌ์œผ๋ฉด ์„ค์น˜ํ•ด ์ฃผ๋ฉฐ /usr/local ์— ์“ฐ๊ธฐ ๊ถŒํ•œ์ด ํ•„์š”ํ•˜๋ฏ€๋กœ ๋ฃจํŠธ๋กœ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    make install

์„ค์ •

์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์œผ๋ฏ€๋กœ ์‹œ์Šคํ…œ ๋ณ€์ˆ˜์— ๋“ฑ๋กํ•ด ์ฃผ๊ธฐ ์œ„ํ•ด ๋‹ค์Œ ๋‚ด์šฉ์„ .bash_profile ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

PY27=/usr/local/python2.7/
export PATH=$PATH:${PY27}/bin
export LD_LIBRARY_PATH=${PY27}/lib:$LD_LIBRARY_PATH
ย 
## Python 3
PY34=/usr/local/python3.4/
export PATH=$PATH:${PY34}/bin
export LD_LIBRARY_PATH=${PY34}/lib:$LD_LIBRARY_PATH

ย 

ย ์„ค์ •์ด ๋๋‚ฌ์œผ๋ฉด ํ˜„์žฌ ์‰˜์— ๋ณ€๊ฒฝ๋œ ์„ค์ •์„ ๋ฐ˜์˜ํ•ฉ๋‹ˆ๋‹ค.

source ~/.bash_profile

ย 

์ด์ œ python2.7 ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์ƒˆ๋กœ ์„ค์น˜ํ•œ python ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

$  python2.7

Python 2.7.11 (default, Apr 22 2016, 12:37:55) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

ย 

ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž ์„ค์น˜

์™ธ๋ถ€ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•  ๋•Œ ํ•„์š”ํ•œ setuptools ์™€ pip ๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

setuptools

  1. ๋‹ค์šด๋กœ๋“œย 

    curl -k -O https://pypi.python.org/packages/source/s/setuptools/setuptools-20.9.0.tar.gz
  2. ์••์ถ• ํ•ด์ œ ๋ฐ ์ด๋™

    tar zxvf setuptools-20.9.0.tar.gz
    cd setuptools-20.9.0
  3. ์„ค์น˜(root ๊ถŒํ•œ ํ•„์š”)

    python2.7 setup.py install

pip

  1. ๋‹ค์šด๋กœ๋“œ

    curl -O -k https://pypi.python.org/packages/source/p/pip/pip-8.1.1.tar.gz
  2. ์••์ถ• ํ•ด์ œ ๋ฐ ์ด๋™

    tar zxvf pip-8.1.1.tar.gz
    cd pip-8.1.1
  3. ์„ค์น˜(root ํ•„์š”)

    python2.7 setup.py install

์ฐธ๊ณ 

ย