|
|
centos7.9安装python3.12版本
* G: r7 K: E" M+ c- i- |6 [$ @, {! h l, g' l) g# q
Python 3.12要求的openssl最低版本为1.1.1,环境中自带的1.0.2k无法使用,所以需要先升级openssl版本至1.1.1以上0 G! ]& s! n# l5 y. B
wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
! \: M! {$ F# a& U1 B7 s--2025-08-08 23:02:41-- https://www.openssl.org/source/openssl-1.1.1k.tar.gz6 B- g! |4 p# L& g% o' F
Resolving www.openssl.org (www.openssl.org)... 34.49.79.89, 2600:1901:0:d50b::
- u* \) U# x: [7 ^+ zConnecting to www.openssl.org (www.openssl.org)|34.49.79.89|:443... connected.
: P8 f( k. A$ s. K3 I; m, {5 L9 |HTTP request sent, awaiting response... 301 Moved Permanently
% n8 k# G/ P8 j/ X/ r* ?) e8 mLocation: https://github.com/openssl/opens ... enssl-1.1.1k.tar.gz [following]
2 J4 E5 W4 L7 {% }2 o5 X--2025-08-08 23:02:43-- https://github.com/openssl/opens ... enssl-1.1.1k.tar.gz
6 q) l9 Z/ _" ]+ S( j9 j( ^3 R) NResolving github.com (github.com)... 20.205.243.1663 X& H, U6 v2 |9 @/ b
Connecting to github.com (github.com)|20.205.243.166|:443... connected.1 L, Z3 B- _- Z
HTTP request sent, awaiting response... 302 Found* m; A' P3 h; p$ e5 Z+ ?
Location: https://release-assets.githubuse ... tion%2Foctet-stream [following]
; p9 n$ @3 x0 s; {--2025-08-08 23:02:43-- https://release-assets.githubuse ... tion%2Foctet-stream
! X' V: {) V1 q7 a8 ~' N1 KResolving release-assets.githubusercontent.com (release-assets.githubusercontent.com)... 185.199.109.133, 185.199.111.133, 185.199.108.133, .../ n0 A8 q, M. g1 ~7 j* U- p
Connecting to release-assets.githubusercontent.com (release-assets.githubusercontent.com)|185.199.109.133|:443... connected.
) w4 Y# d4 {7 S; f- LHTTP request sent, awaiting response... 200 OK
8 f0 p, T+ ?7 q% ^9 pLength: 9823400 (9.4M) [application/octet-stream]
$ O. N4 J' B) Y7 }9 u5 y( ySaving to: ‘openssl-1.1.1k.tar.gz’! \. t( ^% e. z5 F
- V5 x1 S+ P$ ~. X
- @( A! C5 |4 Q6 i3 F100%[=====================================================================================================================================================================================================>] 9,823,400 203KB/s in 44s ( Q6 k* l( v" w' X
! N* @. N" D: U
) g# r2 \1 |' S2025-08-08 23:03:28 (218 KB/s) - ‘openssl-1.1.1k.tar.gz’ saved [9823400/9823400]
9 M: C+ f& Y2 \& n$ ~, Z
8 z( |+ x$ |' S. n2 _: x1 f
: Z1 C, q0 a2 K: `备份文件:
$ Z2 F l; ^+ q& ~9 [& Q: \: m. }7 x1 l7 u4 m/ @
# mv /usr/bin/openssl /usr/bin/openssl.bak/ z- }; \+ c! G) i6 |% m
+ S+ ^' y6 N$ m Z9 b) f' [* ]8 j# ~3 M# w% F+ p/ W4 e( o. V
3 h: u3 Y+ X F- y4 y; _4 {: d
# mv /usr/include/openssl /usr/include/9 j! }0 h3 w8 @$ f3 G- R& J5 W
Display all 163 possibilities? (y or n)
: v' ]" a; A0 m" |. ]# mv /usr/include/openssl /usr/include//openssl.bak: {& k# J/ P. V4 S
9 M1 {1 n6 R4 |! U/ O
9 f% w- N* f! ^6 M) S; g4 _解压openssl8 ~9 h8 g8 t2 z2 \$ ]6 k0 k# n. M
# tar -zxvf openssl-1.1.1k.tar.gz$ ~1 e. b5 T5 V; y. n9 d
1 D1 t# e( N3 p2 Q% ^+ J- W: @! Z( v% G3 S4 [
# cd openssl-1.1.1k/2 d9 i: n5 R. ^1 N" f
# mkdir build
. k7 V z* I- Y( j' `# cd build/
1 I. S9 k. C) C( z" ~3 o( K' c, \
) ]. J# w$ e) u$ H8 l# ../config --prefix=/usr/local/openssl( i4 t4 F& d/ Q$ w
Operating system: x86_64-whatever-linux2; a( Z6 S4 ]" [7 j
Configuring OpenSSL version 1.1.1k (0x101010bfL) for linux-x86_64
" ?9 ^ A$ W! r. C. \. r; ]% LUsing os-specific seed configuration/ O' e4 n/ S2 L: k. [
Creating configdata.pm7 D0 k! H, L7 G/ d9 q6 p( e
Creating Makefile/ L' `( @0 v- K7 |& k$ X: w
! j: g$ e g+ e* \% ^, G5 ]' b6 }% c' h3 m" L+ m; I
**********************************************************************
2 O6 {$ H4 H% R( Z4 L( x*** ***' q' w) W+ y: c
*** OpenSSL has been successfully configured ***
/ T6 f! m" a; `/ g*** ***. o& i. [* R6 F2 o, H6 @
*** If you encounter a problem while building, please open an ***
# r9 h |5 C* s+ K" z3 b*** issue on GitHub <https://github.com/openssl/openssl/issues> ***4 Z2 t+ y% G7 a* {- R3 K
*** and include the output from the following command: ***
, o& _# s3 w7 s3 f, T$ `*** ***4 s+ z! ], A$ A9 G4 R3 Z
*** perl configdata.pm --dump ***" L: B) {3 ?2 J% z1 x
*** ***
& ^8 E: ^! c* U e! |- B# U*** (If you are new to OpenSSL, you might want to consult the ***0 _1 i; K. ` {& b" @1 w$ j2 a
*** 'Troubleshooting' section in the INSTALL file first) ***
5 ?+ \& Y4 W$ y" Q$ |6 w*** ***
* v/ A% C; Q. X& q**********************************************************************( k8 \! z: k% d
" G" a5 o" A/ j# make -j && make install
3 z6 B" G2 Z% R' j
5 ]1 N' D2 F0 g. A/ b$ U7 l, x" U
* e4 X5 s, X2 a8 A1 z4 f做软连接:
2 o8 B5 ^6 a9 W/ a ln -s /usr/local/openssl.1.1.1/bin/openssl /usr/bin/openssl v3 ]: x; u) J$ U+ a
7 i5 H! [# X2 M" }# echo "/usr/local/openssl/lib/" >> /etc/ld.so.conf + b5 C: T8 x" v# c: }
# ldconfig -v* C; t! K. ?6 N8 o. e
ldconfig: Can't stat /libx32: No such file or directory
/ u. s" ~9 V, V2 ?ldconfig: Path `/usr/lib' given more than once
0 Q& b; u+ M' V5 M( Bldconfig: Path `/usr/lib64' given more than once6 g' x- j) [& S5 e& Q/ W4 s1 n, E1 u% P
ldconfig: Can't stat /usr/libx32: No such file or directory
9 K6 s$ ~# P1 O4 j9 F" v/usr/lib64//bind9-export:9 C0 s) V: k* T- p% v& a# H, C% ^
libisccfg-export.so.160 -> libisccfg-export.so.160.2.1
' i( F! T% I9 L$ l/ h
) y7 Z0 D' v% j0 O0 O2 M4 o. }; m# openssl version X( r( s/ ?; m5 Z" ^! {6 x3 i! u
OpenSSL 1.1.1k 25 Mar 2021
. N4 c8 y3 B8 s( @! x$ F- t" [5 y8 X5 q( c) o" c
: }; {/ P: i/ l' m4 m% y) n接下来安装python3.12.10和pip39 G0 d6 t' w* m) v) U" V
下载python3.12.7源代码
) b- h, j$ T# q& N# tar -zxvf Python-3.12.10.tgz
* M, l# Z- Y$ |2 y8 ~
. P) y( |4 e- D0 c! W% A2 k# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make/ ` S# a; J4 P1 K
. W4 r+ X/ E" ]
; Z$ w/ ^2 x% ^ b
( I* @( [4 R4 C
# R6 Z% m# ~" c9 h0 @7 R& v! Z3 X) x
进入解压后的源代码目录1 h Y: d' Z9 j3 W' }! i
; u/ v7 |8 {" L9 u1 ~7 U+ b# b
# cd /usr/src/Python-3.12.10/' V% Y! d1 g" x+ H
5 ?: c) Z; m/ D
' p( A7 ]7 B p6 H
8 V {' }# v, m& D; g6 s2 q- h9 x7 R+ h7 R5 z J
配置
# ~6 P, U7 ]9 j6 k* m# ./configure --prefix=/usr/local/python-3.12.10 --with-openssl=/usr/local/openssl
# f7 Q _! H. }7 L Q3 b) ~: c: J2 t
7 _, H- C/ u& \4 d/ W- F% m, D; {5 a4 U0 G2 u ~* u
编译! j4 x( e. K) U) M; Y4 q
make7 p/ m+ [0 e' D# V! E) T1 T5 H
安装) D% ~/ J0 H1 U8 |/ H
make install
* |6 M9 H6 A# s5 T1 C: t$ z u" q( _( s( s
) @1 ^, X- U. f D9 e0 Q
2 o2 H6 h+ D* v; |) d# make && make install 9 A8 I6 b$ M1 L }9 C$ f' \! {
gcc -std=gnu11 -pthread -c -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Programs/python.o ./Programs/python.c" v1 q/ T7 `5 q/ N! i' o
gcc -std=gnu11 -pthread -c -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Parser/token.o Parser/token.c0 K2 p$ x4 }$ r* q$ d
gcc -std=gnu11 -pthread -c -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Parser/pegen.o Parser/pegen.c
! T1 E2 L$ f8 A+ g) `5 V' Ogcc -std=gnu11 -pthread -c -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Parser/pegen_errors.o Parser/pegen_err
+ }8 @. P/ c3 o& y3 A6 |! B( y3 U
7 D0 i$ L, b% _# H) `* i
" |! z- h) S& I创建软链接
# p8 K$ X* Q4 j- A* P, y. lln -s /usr/src/Python-3.12.7/Python-3.12.7/bin/python3.12 /usr/bin/python3
1 c; q" a. n: K9 a# aln -s /usr/src/Python-3.12.7/Python-3.12.7/bin/pip3 /usr/bin/pip3
" p6 @) ]1 F. N7 e, c9 `! q. O) [- ]) R) D! P
_1 H2 |( L h8 A2 C
验证python3及pip3
' x# v4 `0 t; U! F! f' j( a[root@centos7 Python-3.12.7]# python3 --version
+ K& g4 z) r1 B" l) i7 K5 IPython 3.12.7
. U- ^/ A! o# ?[root@centos7 Python-3.12.7]# pip3 --version$ x6 G- L. q- g: K/ n; y
pip 24.2 from /usr/src/Python-3.12.7/Python-3.12.7/lib/python3.12/site-packages/pip (python 3.12)7 {, p0 `+ s5 a6 G
9 T7 W5 ]1 G4 z1 @* I
bash
: p. G6 c+ ]: p1 ~+ E( {1 H: t/ o/ ?
4 S* N1 H- L1 ?! w7 r' @* b6 q- Y2 Q3 M
5 n& Q/ ~* V1 n, [' o- F4 b
( S+ C* N4 K; A S3 h
0 w1 @3 T0 {) M+ r; O8 v
1 Y$ t/ x& `+ [3 N9 T0 _- b: O$ t1 t
|
|