Compile python

最後更新: 2024-01-15

目錄

  • Centos 6 - Python 3.6
  • Debian - Python 3.10

Centos

 

Centos 6 準備

yum install make gcc

yum install pcre-devel

yum install libffi-devel

yum install openssl-devel

yum install zlib-devel bzip2-devel

Optional

yum install sqlite-devel

P.S.

Python 3.7 要 openssl11-devel

Compile

VERSION=3.6.15           # 22M, 04-Sep-2021

mkdir /usr/src/python; cd !$

wget https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tgz

tar -zxf Python-${VERSION}.tgz

cd Python-${VERSION}

./configure --prefix=/opt/py36 \
  --disable-ipv6 \
  --disable-test-modules \
  --enable-optimizations

說明

--disable-test-modules

disable the building of modules used for internal Python testing
These modules are not necessary for running Python programs,
 they are only used by Python's developers to ensure that the interpreter is working correctly.

Complie with 2 CPU Core

make -j 2

Installation

make altinstall

Notes

altinstall = alternative installation

altinstall skips creating the python link and the manual pages links

自己建立 Link

ln -sfn /opt/py36/bin/python3.6 /usr/bin/python36

ln -sfn /opt/py36/bin/pip3.6 /usr/bin/pip36

Checking

python36 -c "import sqlite3; print(sqlite3.sqlite_version)"

3.6.20

Notes

  • The re, csv module is part of Python's standard library

 


Debain

 

Python 3.10

apt install wget

apt install build-essential \
  libreadline-dev libncursesw5-dev libssl-dev \
  tk-dev libgdbm-dev libc6-dev libffi-dev\
  libbz2-dev zlib1g-dev

apt install libsqlite3-dev

Get Source

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

Config

./configure --prefix=/opt/py310 \
--enable-optimizations --disable-ipv6 \
--disable-test-modules

Test

./python

Fatal Python error: _PySys_InitCore: can't initialize sys module
Python runtime state: preinitialized

Current thread 0x00007f93cde11740 (most recent call first):
  <no Python frame>

去除 ./configure 的 "--enable-optimizations"

 


 

 

Creative Commons license icon Creative Commons license icon