§2023-06-22
§Compile Python from Source
When you are using ubuntu, sometime you have to wait for the most recent stable release of Pyton. We might as well do it by own own.
-
Prerequisites
- Centos
$ sudo dnf install wget yum-utils make gcc openssl-devel bzip2-devel libffi-devel zlib-devel
- Ubuntu 20.04
- sudo apt update
- sudo apt install -y build-essential checkinstall
- sudo apt install libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
- libreadline-gplv2-dev not available now
- ubuntu 22.04
- sudo apt update
- sudo apt install -y build-essential checkinstall
- sudo apt install libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
- Centos
-
get source
- source https://www.python.org/ftp/python/
https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tar.xz
wget https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tar.xz
$ tar xvf src/Python-3.11.4.tar.xz
-
Configure
$ cd Python-3.11.4
$ ./configure --with-system-ffi --with-computed-gotos --enable-loadable-sqlite-extensions
....
....
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/Setup.bootstrap
config.status: creating Modules/Setup.stdlib
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
configure: creating Modules/Setup.local
configure: creating Makefile
configure:
If you want a release build with all stable optimizations active (PGO, etc),
please run ./configure --enable-optimizations
$ ./configure --enable-optimizations
- Compile
- 2023-07-20, compile Python-3.11.4
- hc4Odroid, 4G, 256G SSHD , ubuntu 22.04 Jammy
$ time make -j 6
real 26m59.085s
user 68m30.229s
sys 2m14.682s
- 2023-07-20, compile Python-3.10.12
- OrangePi5 Plus 8G 256G PCIeSSD running Deabin Bookworm
- python 3.11.14 can not fulfill mongo compiling requirements
```bash
$ time make -j 10
real 5m24.631s
user 20m17.941s
sys 0m50.202s
$ wget https://www.python.org/ftp/python/3.10.12/Python-3.10.12.tar.xz
- 2023-07-11
- orangepi5plus, 8GMB. deabin bookworm
```bash
time make -j 10
real 5m24.675s
user 21m51.101s
sys 0m53.446s
- 2023-06-30
- Intel(R) Celeron(R) CPU J1900 @ 1.99GHz
- 4G Mem
real 3m35.163s
user 11m44.453s
sys 0m39.757s
- 2023-06-29
- on orange pi 5 plus, 8cps, 2.0Mhz, 16G memory, 256G PCiSSD
$ time make -j 10 // ${nproc} + 2
real 5m55.265s
user 23m30.905s
sys 0m56.811s
$ time make -j 6 // ${nproc} + 2
- 2023-06-23, odroid-HC4 , 4 cpus, 4G mem, swap 8G
$ time make -j 4
real 32m47.064s
user 67m16.575s
sys 2m3.888s
- 2023-06-23, odroid-N2, 6 cpus, 4G mem, swap 4G
$ time make -j 8
real 14m39.211s
user 37m3.568s
sys 1m53.524s
$ time make -j 8
real 14m27.417s
user 48m8.730s
sys 1m49.545s
- AMD a6-5200, CPU 2MHZ, 12G mem, 9G swap
$ time make -j 6
real 15m50.643s
user 48m0.766s
sy- -1m53.677s
- on Surface Pro, with 4 cores and 8G mem, Clock Speed 1.9 Ghz
real 3m49.309s
user 9m43.429s
sys 0m24.006s
- on orange pi 5 plus, 8cps, 2.0Mhz, 16G memory
$ time make -j 10 // ${nproc} + 2
real 7m26.704s
user 28m10.589s
sys 1m3.465s
$ time make -j 8
real 7m0.917s
user 25m53.621s
sys 0m59.353s
$ time make -j 6 --> compiling verion 3.10.12
real 7m9.152s
user 24m29.228s
sys 0m53.549s
- odroid-h2, 2022-08-25
$ time make -j 6 // ${nproc} + 2
real 7m11.677s
user 16m16.056s
sys 0m55.503s
¶ Eviroment Control
$ ./python -m venv ~/PYTHON-3.11.4
alexlai@orangepi5plus:~/build/Python-3.11.4$ $ pwd
/opt/xfs/home/alexlai/build/Python-3.11.4
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
alexlai@orangepi5plus:~/build/Python-3.11.4$ source ~/PYTHON-3.11.4/bin/activate
(PYTHON-3.11.4) alexlai@orangepi5plus:~/build/Python-3.11.4$ echo $PATH
/opt/xfs/home/alexlai/PYTHON-3.11.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
(PYTHON-3.11.4) alexlai@orangepi5plus:~/build/Python-3.11.4$ which python
/opt/xfs/home/alexlai/PYTHON-3.11.4/bin/python
(PYTHON-3.11.4) alexlai@orangepi5plus:~/build/Python-3.11.4$ which python3
/opt/xfs/home/alexlai/PYTHON-3.11.4/bin/python3
(PYTHON-3.11.4) alexlai@orangepi5plus:~/build/Python-3.11.4$ which pip
/opt/xfs/home/alexlai/PYTHON-3.11.4/bin/pip
(PYTHON-3.11.4) alexlai@orangepi5plus:~/build/Python-3.11.4$ which pip3
/opt/xfs/home/alexlai/PYTHON-3.11.4/bin/pip3