[Rocky] Python-3.12.7 소스 설치






1. 개요

Python 3.12.7 소스 설치합니다.







2. 버전

Rocky 9.5
Python 3.12.7







3. Python





3-1. 다운로드

URL: https://www.python.org/downloads/


# dnf -y install wget
# wget https://www.python.org/ftp/python/3.12.7/Python-3.12.7.tgz




3-2. 설치

# dnf -y install tar gcc zlib-devel
# tar xvfz Python-3.12.7.tgz
# cd Python-3.12.7
# ./configure –prefix=/apps/python/3.12.7 –enable-shared –enable-optimizations
# make -j
# make install
# cd /apps/python/3.12.7/bin/
# ln -sf python3.12 python
# ln -sf pip3.12 pip


./configure --prefix=/apps/python/3.12.7 --enable-shared --enable-optimizations
1. --prefix
  - 설명: Python 설치 디렉토리 지정
  - 사용 목적: 여러 버전 관리 또는 비표준 경로 설치

2. --enable-shared
  - 설명: 공유 라이브러리(.so) 생성
  - 사용 목적: Python 임베딩 또는 동적 로드 기능 필요 시

3. --enable-optimizations
  - 설명: 컴파일 최적화 활성화 (-O2, -O3 플래그 등)
  - 사용 목적: Python 성능 향상

make -j
  1. -j
  - 설명: 병렬 컴파일
  - 사용 목적: 빌드 속도 단축







4. 환경 변수





4-1. Shell Profile




4-1-1. 설정

# vim /apps/profile.d/python-3.12.7.sh


+ #!/bin/sh
+ PYTHONHOME=/apps/python/3.12.7
+ PATH=${PYTHONHOME}/bin:${PATH}
+ LD_LIBRARY_PATH=${PYTHONHOME}/lib:${LD_LIBRARY_PATH}
+ export PYTHONHOME PATH LD_LIBRARY_PATH



4-1-2. 확인

# source /apps/profile.d/python-3.12.7.sh
# python –version

Python 3.12.7


# pip –version

pip 24.2 from /apps/python/3.12.7/lib/python3.12/site-packages/pip (python 3.12)




4-2. Environment modules




4-2-1. 설정

# mkdir /usr/share/Modules/modulefiles/python
# vim /usr/share/Modules/modulefiles/python/3.12.7

#%Module

# Module description
proc ModulesHelp { } {
    puts stderr "This module sets up the environment for Python 3.12.7."
}

module-whatis "Sets up Python 3.12.7 environment."

# Set PYTHONHOME
setenv PYTHONHOME /apps/python/3.12.7

# Prepend to PATH
prepend-path PATH /apps/python/3.12.7/bin

# Prepend to LD_LIBRARY_PATH
prepend-path LD_LIBRARY_PATH /apps/python/3.12.7/lib



4-2-2. 확인

# module avail python

-------------------- /usr/share/Modules/modulefiles ---------------------
python/3.12.7


# module load python/3.12.7
# python –version

Python 3.12.7


# pip –version

pip 24.2 from /apps/python/3.12.7/lib/python3.12/site-packages/pip (python 3.12)







5. ERROR





5-1. wget 명령어 없는 경우




5-1-1. 내용

# wget https://www.python.org/ftp/python/3.12.7/Python-3.12.7.tgz

-bash: wget: command not found



5-1-2. 해결 방법

# dnf -y install wget




5-2. tar 명령어 없는 경우




5-2-1. 내용

# tar xvfz Python-3.12.7.tgz

-bash: tar: command not found



5-2-2. 해결 방법

# dnf -y install tar




5-3. gcc 없는 경우




5-3-1. 내용

# ./configure –prefix=/apps/python/3.12.7 –enable-shared –enable-optimizations

checking MACHDEP... "linux"
checking for gcc... no
checking for cc... no
checking for cl.exe... no
checking for clang... no
configure: error: in `/root/Python-3.12.7':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details



5-3-2. 해결 방법

# dnf -y install gcc




5-4. zlib-devel 없는 경우




5-3-1. 내용

# make install

Traceback (most recent call last):
  File "<frozen zipimport>", line 510, in _get_decompress_func
ModuleNotFoundError: No module named 'zlib'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen zipimport>", line 558, in _get_data
  File "<frozen zipimport>", line 513, in _get_decompress_func
zipimport.ZipImportError: can't decompress data; zlib not available

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "<frozen runpy>", line 222, in run_module
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 112, in _get_module_details
  File "<frozen zipimport>", line 137, in get_code
  File "<frozen zipimport>", line 692, in _get_module_code
  File "<frozen zipimport>", line 560, in _get_data
zipimport.ZipImportError: can't decompress data; zlib not available
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/root/Python-3.12.7/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
             ^^^^^^^^^^^^^^^^^
  File "/root/Python-3.12.7/Lib/ensurepip/__init__.py", line 284, in _main
    return _bootstrap(
           ^^^^^^^^^^^
  File "/root/Python-3.12.7/Lib/ensurepip/__init__.py", line 200, in _bootstrap
    return _run_pip([*args, *_PACKAGE_NAMES], additional_paths)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/Python-3.12.7/Lib/ensurepip/__init__.py", line 101, in _run_pip
    return subprocess.run(cmd, check=True).returncode
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/Python-3.12.7/Lib/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/root/Python-3.12.7/python', '-W', 'ignore::DeprecationWarning', '-c', '\nimport runpy\nimport sys\nsys.path = [\'/tmp/tmpbvwbu1r2/pip-24.2-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/tmp/tmpbvwbu1r2\', \'--root\', \'/\', \'--upgrade\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 1.
make: *** [Makefile:2027: install] Error 1



5-3-2. 해결 방법

# dnf -y install zlib-devel



Leave a Comment