找回密码
 注册
查看: 465|回复: 2

centos7.9安装python3.12版本

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2025-8-8 17:00:01 | 显示全部楼层 |阅读模式
centos7.9安装python3.12版本
9 d* z( ?8 s7 T( p6 n  S( l0 Q6 W3 h) G* X2 r* L% T
Python 3.12要求的openssl最低版本为1.1.1,环境中自带的1.0.2k无法使用,所以需要先升级openssl版本至1.1.1以上, `+ X, Q! X9 z7 V7 G% d
wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
% E8 j) ^6 h" P- R--2025-08-08 23:02:41--  https://www.openssl.org/source/openssl-1.1.1k.tar.gz
/ t; [3 |. T$ D0 S, G2 U( b9 mResolving www.openssl.org (www.openssl.org)... 34.49.79.89, 2600:1901:0:d50b::% K2 J  x1 U8 O/ t. D  i) ^
Connecting to www.openssl.org (www.openssl.org)|34.49.79.89|:443... connected.
& ]7 L. o- N2 f' y. m/ Q  e! r& s$ d6 UHTTP request sent, awaiting response... 301 Moved Permanently
2 O; I' T# N* Q( c$ _$ B7 yLocation: https://github.com/openssl/opens ... enssl-1.1.1k.tar.gz [following]
$ C9 @, }, O, k8 X5 b8 k$ C--2025-08-08 23:02:43--  https://github.com/openssl/opens ... enssl-1.1.1k.tar.gz
% e/ K  o8 l/ F6 s; IResolving github.com (github.com)... 20.205.243.166
& i2 V# |" \& L  K0 eConnecting to github.com (github.com)|20.205.243.166|:443... connected.
% G% J9 ~* w5 s! X- KHTTP request sent, awaiting response... 302 Found
  r& h6 {2 h2 cLocation: https://release-assets.githubuse ... tion%2Foctet-stream [following]& [/ \& \# l- z: O  q
--2025-08-08 23:02:43--  https://release-assets.githubuse ... tion%2Foctet-stream
" Y; r7 ~1 o! RResolving release-assets.githubusercontent.com (release-assets.githubusercontent.com)... 185.199.109.133, 185.199.111.133, 185.199.108.133, ...
4 c( k% v# M) P2 i# s0 DConnecting to release-assets.githubusercontent.com (release-assets.githubusercontent.com)|185.199.109.133|:443... connected.  a8 q: N9 X, f4 Z) w
HTTP request sent, awaiting response... 200 OK
% _, H4 E9 J% y$ C; Z1 f8 k. ELength: 9823400 (9.4M) [application/octet-stream]( n4 P6 y5 F+ c$ @) D7 g
Saving to: ‘openssl-1.1.1k.tar.gz’" o' x. d2 {; t( Q( E- H

: ~; ^, B' P; e, d
/ P6 \4 _  {7 v7 J2 Z$ A# W( i
100%[=====================================================================================================================================================================================================>] 9,823,400    203KB/s   in 44s   
' F; X, b  _+ w3 Y# h/ L$ X! Q- f& T$ [

$ H3 Z5 I7 ~# h/ ?7 X* V/ t2025-08-08 23:03:28 (218 KB/s) - ‘openssl-1.1.1k.tar.gz’ saved [9823400/9823400]
3 ^/ D2 {: `! V- }! y' C: O# W, f9 m0 ~$ {+ g9 y: a

) Q# o3 H1 ]0 m8 R6 b$ ]. m备份文件:
9 r0 u- J2 v- }! @1 N
' V. M: e& l& ~0 O- _( V5 i# mv /usr/bin/openssl /usr/bin/openssl.bak
+ m$ H1 ^% S1 Y4 @4 A, F" s1 E& F6 V
  k! r  j% |4 h, X# E
7 ~, u) t+ ^" I; x3 @( q# ]% ^# B
# mv /usr/include/openssl /usr/include/  h. t" e, a7 A  G6 j9 H2 J2 u
Display all 163 possibilities? (y or n)
9 x. Z* D8 a: w# mv /usr/include/openssl /usr/include//openssl.bak
, ?  I5 Y0 i- ~" U7 \3 B! O4 V: R, S, d- C0 a  N) Y' w& k& F7 p

8 ?& T9 X0 h8 T  _9 X解压openssl
' R2 `9 w6 R1 N5 }% q  V( C# tar -zxvf openssl-1.1.1k.tar.gz0 m* z/ j. o3 ]5 \

8 @1 |' ]) h0 a& A( w7 |
+ I9 p$ o# n- j5 ^8 K2 X
# cd openssl-1.1.1k/& A* [: c4 B8 Q3 C7 |& O0 b2 n
# mkdir build
2 f5 N! |+ T+ _! W# cd build/
3 b. F7 w$ M8 c9 f* D9 D, h. K: c6 }5 `5 X# X( m
# ../config --prefix=/usr/local/openssl0 v0 P+ |3 G$ i/ Q& m3 Z# l: n
Operating system: x86_64-whatever-linux2
1 E, k, P- s% m  J/ @: {- b& RConfiguring OpenSSL version 1.1.1k (0x101010bfL) for linux-x86_64
; n  E3 O2 I' N# [; g! oUsing os-specific seed configuration/ h! K0 p5 ~4 k  N
Creating configdata.pm
3 r0 u4 c4 H; ^6 I6 KCreating Makefile' r9 I0 S4 Q( B2 k* {5 w3 D
& ^9 ~5 J+ ]- j- ]0 J$ X5 e/ Q1 K7 T
  x" ^+ T2 s9 t: j5 K: D4 Q4 c
**********************************************************************# ^8 ]  |- n8 a3 _, O* g! W
***                                                                ***9 m3 E& c% v+ h
***   OpenSSL has been successfully configured                     ***& g* f$ J* W( P# r0 Q6 ~# g+ L
***                                                                ***5 L. K, F0 O2 s% B9 d
***   If you encounter a problem while building, please open an    ***; I: z7 i5 D$ M) H8 h8 A' H4 M; H
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***# M- q2 I% c  p; P6 U
***   and include the output from the following command:           ***% \! q+ e0 K) \6 r, x0 u5 Q
***                                                                ***5 H- d* _6 J: \) ^( U) t8 S  W
***       perl configdata.pm --dump                                ***
- L; P* Q# ]) z/ U. L***                                                                ***
& n( \- X4 t; c) p9 r***   (If you are new to OpenSSL, you might want to consult the    ***0 U( C& o+ Y- A' l
***   'Troubleshooting' section in the INSTALL file first)         ***
3 W* l3 j# Z: U8 u***                                                                ***
, t$ I$ d6 g0 y; Q' T**********************************************************************
' ~7 V9 n2 R5 w5 f, b* @# u: s6 Z4 `
# make -j && make install
2 j$ E, R  \, X! y- O/ k/ E

  z4 H! n0 {9 ?

) @; |  h4 n8 E1 h- W  J9 j做软连接:7 }/ N5 O' W8 I4 [; P" a/ T
ln -s /usr/local/openssl.1.1.1/bin/openssl /usr/bin/openssl
3 ]6 f# X0 Y/ x
6 X" B  T: ^& S2 h
# echo "/usr/local/openssl/lib/" >> /etc/ld.so.conf
" Y; ^0 M5 J! ^0 S0 n7 e# ldconfig -v* y. k, ~+ E" f6 ]
ldconfig: Can't stat /libx32: No such file or directory
9 a$ Q( m& C4 W' i$ L- ]" {6 Vldconfig: Path `/usr/lib' given more than once* A: y# U" ]! L" Z* p( J
ldconfig: Path `/usr/lib64' given more than once9 Q  Z! W2 Y0 F) u. r$ m2 _
ldconfig: Can't stat /usr/libx32: No such file or directory* Q( \3 J; G5 g' w- z4 T' Y
/usr/lib64//bind9-export:0 _) n" E& P5 @8 ]# m3 L, G) G. j
        libisccfg-export.so.160 -> libisccfg-export.so.160.2.1, s% V3 @" |& ?& [! Y1 r4 X
5 ]* ]! s1 z& w) W4 \
# openssl version+ M9 p3 N" U1 _4 g
OpenSSL 1.1.1k  25 Mar 2021! S  w- W2 X  R8 Q

8 C$ ^' ?0 E: [- [0 G& M0 I' `3 T* V* u4 `6 k+ j
接下来安装python3.12.10和pip3# t0 q& U6 y* r. ?9 _7 q& M
下载python3.12.7源代码* j  j% X9 x) K7 x! e
# tar -zxvf Python-3.12.10.tgz 7 ?; I( T4 k% s! M; |: \
3 M: D+ g2 E# N$ D: X3 n! x5 l# \
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make$ s0 @& S9 k+ L$ w$ ?( z
8 q5 y: V- Y6 f' F8 h

1 }  o' }3 [: z, n6 X, c8 D' d) q
- j6 u1 Z1 T0 f+ R& A4 ^
( G: I1 _3 b1 |

$ s* ^0 u% O1 A. Y/ b0 G" {- Z2 C进入解压后的源代码目录# D1 n4 Y) Y+ ]+ O
5 t9 N4 d+ r3 r$ u/ }  M' h
# cd /usr/src/Python-3.12.10/
3 J* S: R/ T7 h- t( ]2 s9 G/ N# ]3 W1 A0 H: O. A+ q1 f

4 {2 }; Q3 f8 J$ L% E5 ?( [) m( T+ _6 w& g1 a8 n( z, y2 q

/ ^0 p* i8 \8 g配置" k. A: u) W7 v# P* D
# ./configure --prefix=/usr/local/python-3.12.10 --with-openssl=/usr/local/openssl
$ B) l% B, O$ ], \
5 a6 s. X% u% u4 F$ i' @$ j! p

& o, r  [4 p; C; A; A/ N) r编译$ z/ Z! M* {( M# e# Q
make
9 ~2 i3 B/ s7 H! R安装% s" D' I5 u1 P
make install
& Y, R9 b. ^: t4 v# }
- a* B4 D8 H& a3 J) w$ y' E! W

! }% E9 [3 o1 M0 O3 j8 }- n0 j
# make && make install
# l0 ~# a4 B% agcc -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
0 A, {2 a* t& L- P! o% xgcc -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.c/ l: x  u# T0 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/pegen.o Parser/pegen.c* V, y" u+ j0 N
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_errors.o Parser/pegen_err) y/ i$ k9 f- e' Q9 j4 o/ Q# W4 r

2 v' U" `3 T, `& B8 n! }, x  D5 V! t# E. A; i. n+ T

% d# G* R. Z' W0 H5 e/ A( E7 O. @; t创建软链接
7 U& w7 W$ B. w' u7 ^ln -s /usr/src/Python-3.12.7/Python-3.12.7/bin/python3.12 /usr/bin/python3. Z$ Z7 ^( N" a8 M& w8 G
ln -s /usr/src/Python-3.12.7/Python-3.12.7/bin/pip3 /usr/bin/pip31 f0 |/ j; [: k8 u: `
- O, Y# d( V1 |
* x# \' b+ F& y2 W
验证python3及pip3( A7 s2 `* v1 T% a" _
[root@centos7 Python-3.12.7]# python3 --version
: A$ [) e+ D* c+ mPython 3.12.7; F8 t8 p7 w0 o; D( p
[root@centos7 Python-3.12.7]# pip3 --version
& O# w5 ^: G# apip 24.2 from /usr/src/Python-3.12.7/Python-3.12.7/lib/python3.12/site-packages/pip (python 3.12)! ~: b' ^$ Y3 M& S3 Y! B

3 B9 U/ p7 g! _* W  X5 jbash$ z4 H1 W- x) X, F

! g- G+ J3 U- l$ ^" l. W/ {( M' A  j) v% D3 _5 H$ b
* N, l3 G7 L( V# W9 @, k2 Y. C) f
8 D% }9 Y/ Z# ~$ F  @+ R
, A9 S% |: K& G% u5 I' V

" M# V3 A! B1 O5 D3 t
( R5 W' r$ ]- e% p1 \

7 R/ O/ @+ ^  |3 }7 h  j

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2025-8-8 17:00:02 | 显示全部楼层
# ln -s /usr/local/python-3.12.10/bin/python3.12 /usr/bin/python3.12
: C4 g: e3 ?. d# [7 ^7 I# ln -s /usr/bin/python3.12 /usr/bin/python
3 L" x6 n- e6 {+ t5 m# ln -s /usr/bin/python3.12 /usr/bin/python
8 V$ d/ ^+ `1 b3 c& g- T2 ~ ln -sf /usr/bin/python3.12 /usr/bin/python
" ^% X6 [0 g( w( V

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2025-8-8 17:00:03 | 显示全部楼层
# ln -s /usr/local/python-3.12.10/bin/pip3 /usr/bin/pip
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 00:40 , Processed in 0.019367 second(s), 21 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表