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

centos7.9安装python3.12版本

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2025-8-8 17:00:01 | 显示全部楼层 |阅读模式
centos7.9安装python3.12版本' B$ W3 M8 V( E- T
5 j' t4 m; F; y1 y" Z
Python 3.12要求的openssl最低版本为1.1.1,环境中自带的1.0.2k无法使用,所以需要先升级openssl版本至1.1.1以上7 m+ G3 E7 H4 x5 {
wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
. F5 q; P4 W" V4 i8 W. B--2025-08-08 23:02:41--  https://www.openssl.org/source/openssl-1.1.1k.tar.gz
, c* F; r0 L- K; G, MResolving www.openssl.org (www.openssl.org)... 34.49.79.89, 2600:1901:0:d50b::) A1 K8 A, G. q- A/ V1 l) N: y
Connecting to www.openssl.org (www.openssl.org)|34.49.79.89|:443... connected.- r* @  w* L4 H
HTTP request sent, awaiting response... 301 Moved Permanently8 X, ^8 A0 S4 |& ]
Location: https://github.com/openssl/opens ... enssl-1.1.1k.tar.gz [following]
; W- t* r6 R3 R6 f7 m3 m- J; n( w--2025-08-08 23:02:43--  https://github.com/openssl/opens ... enssl-1.1.1k.tar.gz1 t* U4 l/ o. L# K$ a
Resolving github.com (github.com)... 20.205.243.166, P" ?& j' D/ x/ B$ Q% b
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
+ B9 a, n9 n8 |4 c3 VHTTP request sent, awaiting response... 302 Found- {, r' l6 }& [9 h
Location: https://release-assets.githubuse ... tion%2Foctet-stream [following]3 @; E* x- j3 K! U& X8 h
--2025-08-08 23:02:43--  https://release-assets.githubuse ... tion%2Foctet-stream* D+ l3 F/ a' A) U5 n  g5 g
Resolving release-assets.githubusercontent.com (release-assets.githubusercontent.com)... 185.199.109.133, 185.199.111.133, 185.199.108.133, ...! f! J+ j1 y1 f, t. [
Connecting to release-assets.githubusercontent.com (release-assets.githubusercontent.com)|185.199.109.133|:443... connected.3 \# f, O: P6 i1 |: A
HTTP request sent, awaiting response... 200 OK
5 |+ ~; f5 D# |4 o# kLength: 9823400 (9.4M) [application/octet-stream]
( B' r1 a7 t! B) X: L4 [Saving to: ‘openssl-1.1.1k.tar.gz’; u! I/ H( j" k/ C/ i
  D  T2 v% w9 H% X  x  q# z
) w# S0 ?+ j& U. h
100%[=====================================================================================================================================================================================================>] 9,823,400    203KB/s   in 44s    ; g! a2 ^; s/ ~

: y8 Z5 ]. o6 ?5 t
3 d2 y( M  O, O) h0 V# i: O% g; s
2025-08-08 23:03:28 (218 KB/s) - ‘openssl-1.1.1k.tar.gz’ saved [9823400/9823400], {; F+ @. Y8 ]6 `5 R
/ K9 f8 J/ u5 p

7 b0 ~1 }6 a1 X; y- E5 x  ?备份文件:
) Z/ r: N8 F6 s2 i  M2 t( J' ^4 n8 e. O+ g" W
# mv /usr/bin/openssl /usr/bin/openssl.bak
3 x4 I8 t$ g. l& a/ t  p; V: Q) C8 Y& W  E. f. E
4 x9 B0 v7 [0 |; l

) ]: D, c4 O8 ^* I7 k# mv /usr/include/openssl /usr/include/
  {; S3 p' [7 ADisplay all 163 possibilities? (y or n)
7 c# N" {% @4 d/ _* r# R* v, y$ P# mv /usr/include/openssl /usr/include//openssl.bak5 S* U9 F( z& G' `$ h$ O+ @# ]
+ h; }0 {" U+ W4 \! W

+ ?( `  G; H$ t4 _$ ?! W解压openssl
9 |) N4 X* C" H/ o; E* Z0 O! i# tar -zxvf openssl-1.1.1k.tar.gz' F( }' y. X; _* Z& t+ e, J

2 `/ q! V2 I+ ~+ H  M  ]# s
  g8 _8 u+ J, V( V
# cd openssl-1.1.1k/' Z9 _1 J+ e9 M5 y. K
# mkdir build
' j2 O8 f* ^% u5 @4 ^9 _# cd build/
/ t5 m" t( [% S* f! E; s0 g6 N) N0 ]
# ../config --prefix=/usr/local/openssl6 h0 e8 A) l/ Q) i2 I' @2 N
Operating system: x86_64-whatever-linux2) o: D/ p5 Z1 g3 C
Configuring OpenSSL version 1.1.1k (0x101010bfL) for linux-x86_645 M1 z+ q6 n. w/ U- _3 j
Using os-specific seed configuration: Y& O# }+ R7 a
Creating configdata.pm) w7 Z& T0 ~$ c) q/ P
Creating Makefile
" F# Y5 d5 M3 K3 G3 n7 x) |" N5 ^0 i6 C' M

) H0 G& k8 L7 A5 v% C! o- S**********************************************************************6 c; y9 w2 C2 e; q
***                                                                ***6 j6 p. E6 e, e% o  w+ k, W8 V0 p
***   OpenSSL has been successfully configured                     ***7 C! Y3 K/ J, u& d$ M
***                                                                ***
0 [  E9 X' X7 X- [, s***   If you encounter a problem while building, please open an    ***" S0 j+ Z" F+ P1 H- f
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
$ B! a3 a7 O0 i' }) A. K4 j" {0 f***   and include the output from the following command:           ***- k  W6 i& z# d
***                                                                ***/ e# ^6 b8 @, e+ `, X2 ]
***       perl configdata.pm --dump                                ***4 O4 l2 l/ ]4 y9 a
***                                                                ***
+ r$ m& j. J% i1 j; f2 G) W***   (If you are new to OpenSSL, you might want to consult the    ***
6 W8 U2 X" V2 S# _% K. B- Q***   'Troubleshooting' section in the INSTALL file first)         ***- l0 m% b  p8 W1 d
***                                                                ***% V6 X0 w# d9 s4 @; A  d
**********************************************************************
9 [! ]) G8 U" _: W% R( @% i2 K% h4 w
# make -j && make install
5 v+ `/ Y. S' ]! S
3 e6 S# n1 W  C" q* m3 k
2 K8 j- z3 c! P9 w; M6 f& t
做软连接:! x% z* `) `/ o
ln -s /usr/local/openssl.1.1.1/bin/openssl /usr/bin/openssl

6 E* T# M! v, @5 y0 n  s  I
# z) J' j* o4 q! @7 ?8 I# echo "/usr/local/openssl/lib/" >> /etc/ld.so.conf " u+ D: h2 b  b8 v0 V
# ldconfig -v, f1 l+ G  I/ d6 N! `1 I
ldconfig: Can't stat /libx32: No such file or directory6 h# v% L* \/ Q& ?' t, j5 N8 U
ldconfig: Path `/usr/lib' given more than once
- B. R: F! F2 J6 ?$ C9 ^ldconfig: Path `/usr/lib64' given more than once/ P. U5 h" n2 i. `* e9 Y/ K9 ?
ldconfig: Can't stat /usr/libx32: No such file or directory- ~; \5 N/ V% B* a0 d+ E3 r' d
/usr/lib64//bind9-export:
7 N( g, a& ?" A( {5 o+ z, y        libisccfg-export.so.160 -> libisccfg-export.so.160.2.11 f/ Y8 A5 z: n9 c
% c- M1 i1 Q5 ~- b: W, ]  ^
# openssl version
( o6 x& a: {/ t& B/ }# iOpenSSL 1.1.1k  25 Mar 2021) o9 p$ f2 M2 j5 m% \, H# Y% u
: d7 |9 Q8 ]8 \# r3 D$ U: h
) ?; l' V, H9 o8 k1 ]5 M
接下来安装python3.12.10和pip39 _7 \. I( U0 w+ Q2 X+ A5 s
下载python3.12.7源代码
+ V: u' z$ x% c0 P# tar -zxvf Python-3.12.10.tgz
7 {7 T  S* `& m& b) w7 C* L0 V. c. K2 T3 z& }
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make$ R% U7 q4 ]- L5 Z4 d

" v$ v7 F5 y% J$ P$ \$ A$ I
7 l" s1 M& a' J/ m" P% ^

" G7 N# y0 B: [
! z/ `  u* w1 L
0 x6 j" j! j2 G) h0 u
进入解压后的源代码目录2 u! P9 e7 W/ X) L  m, W

+ K" n6 y$ [" H; n5 z/ f5 F& b# t' ~# cd /usr/src/Python-3.12.10/
& P+ [0 {6 c3 m- _/ v: Z' _5 W  `( ]2 B6 `* N1 W, p+ a6 ^% d3 G

+ g# w9 r2 o* Y. p
9 R& B9 E; ^3 Q: t" ?! z' A( A

# J; _" N! B% N: o' R/ d配置
) E( ]1 R# e- T, W/ O# ./configure --prefix=/usr/local/python-3.12.10 --with-openssl=/usr/local/openssl 5 T8 r( Q* j/ {7 h3 e* ~

. I  H% b" B: g9 @0 n

' i) Q2 n/ I  c) Z* o$ |" f1 c$ F' a, Q编译
4 b/ a  l* |- c. V2 N, t2 i  s* amake% s9 i- y* |+ R" R" J
安装6 X" N7 u8 z2 s" j, F
make install& @( u& P6 r% T$ x% L7 a5 H

2 ]/ D' G: M. j0 b1 h9 U
: g5 t: F+ U. e

/ G2 W) c) P. E0 X: `# make && make install
( w" b  L4 _& P4 z0 h% l2 Pgcc -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
' |% d$ S' r, Tgcc -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
, E* _( _- L+ egcc -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
, b4 K, o4 r! H3 w7 _% Hgcc -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* W# r9 c4 e/ A- \5 o* T
+ [) f% ^8 @* q8 a5 K
5 U/ z: q- M: b# @
+ v9 G. O7 M' {
创建软链接
8 [: N% p  _- |ln -s /usr/src/Python-3.12.7/Python-3.12.7/bin/python3.12 /usr/bin/python3
- U3 A; J' q& `$ p3 K* M, ]9 [: Tln -s /usr/src/Python-3.12.7/Python-3.12.7/bin/pip3 /usr/bin/pip3! k) B+ Z% F0 P9 p6 K9 h6 L
0 `! n/ t8 M( j8 s# G2 q5 `# C" z
* R6 U& q; z5 p# j2 i  _+ ~6 M
验证python3及pip3
+ t! |/ S0 m; R/ f0 M# e* f[root@centos7 Python-3.12.7]# python3 --version4 C: s5 N, l+ Y
Python 3.12.7  C- U: I% P. n3 Q! A
[root@centos7 Python-3.12.7]# pip3 --version
3 [+ H2 H* K7 ^* U8 _6 K5 U4 B- dpip 24.2 from /usr/src/Python-3.12.7/Python-3.12.7/lib/python3.12/site-packages/pip (python 3.12)
5 \7 u; f# p8 s- ^' o
; i- U, q) `* tbash; h6 y2 E' Z$ s) J1 e6 R0 q( Q
- g1 y7 w7 q$ w9 x

8 Z3 A* J' x8 t8 @+ @0 J- n" \- }7 X0 r& T' v; i

' r( _: k; Y! k- _  W; r* _4 q; j5 l' s! \1 w* X" ~! I

! m  G. h( a$ O
6 G0 h, i& F+ n' U8 A: \
* `, _9 d# {0 u

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
5 C0 `( g8 b4 A# ln -s /usr/bin/python3.12 /usr/bin/python
% x# i" Q+ p! m& ?( ^$ W& J4 o# ln -s /usr/bin/python3.12 /usr/bin/python
0 E. O3 N9 \4 C6 h ln -sf /usr/bin/python3.12 /usr/bin/python& z* V* N' i" Z5 Y6 Y" }: Z! P

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:46 , Processed in 0.015289 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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