银河麒麟高级服务器操作体系(通用)安装和编译指定的python3版本 ...

打印 上一主题 下一主题

主题 642|帖子 642|积分 1926

前言
1、对于一些场景中体系自带的python3.7.5版本无法满足使用需求,必要在情况中安装,编译指定版本的python3,以下详细列出了python3源码编译,安装,以及情况变量配置和使用步骤。
2、以下使用V10 SP3 x86架构操作体系做演示,对于不同架构,不同版本的体系,安装步骤同理!

一 体系情况

  1. [root@localhost ~]# nkvers
  2. ############## Kylin Linux Version #################
  3. Release:
  4. Kylin Linux Advanced Server release V10 (Lance)
  5. Kernel:
  6. 4.19.90-52.22.v2207.ky10.x86_64
  7. Build:
  8. Kylin Linux Advanced Server
  9. release V10 (SP3) /(Lance)-x86_64-Build23/20230324
  10. #################################################
复制代码
二 安装python3.12.4

2.1 安装编译必要的依赖包

  1. 如果网络可以正常连接互联网,直接执行,如果不能访问外网,需要将ISO镜像文件配置成本地yum源!!
  2. [root@localhost ~]# yum install libffi-devel tcl-devel tk-devel perl-CPAN openssl-devel readline-devel sqlite-devel openssl -y
复制代码
2.2 下载官网目前最新的python源码包

  1. [root@localhost ~]# wget https://www.python.org/ftp/python/3.12.4/Python-3.12.4.tar.xz
  2. --2024-07-04 09:15:09--  https://www.python.org/ftp/python/3.12.4/Python-3.12.4.tar.xz
  3. 正在解析主机 www.python.org (www.python.org)... 146.75.112.223, 2a04:4e42:8c::223
  4. 正在连接 www.python.org (www.python.org)|146.75.112.223|:443... 已连接。
  5. 已发出 HTTP 请求,正在等待回应... 200 OK
  6. 长度:20659356 (20M) [application/octet-stream]
  7. 正在保存至: “Python-3.12.4.tar.xz”
  8. Python-3.12.4.tar.xz                            100%[=====================================================================================================>]  19.70M  1.48MB/s  用时 43s     
  9. 2024-07-04 09:15:53 (467 KB/s) - 已保存 “Python-3.12.4.tar.xz” [20659356/20659356])
复制代码
2.3 解压Python-3.12.4.tar.xz

  1. [root@localhost ~]# ls
  2. anaconda-ks.cfg  initial-setup-ks.cfg  Python-3.12.4.tar.xz  test.py
  3. [root@localhost ~]#
  4. [root@localhost ~]#
  5. [root@localhost ~]# tar xf Python-3.12.4.tar.xz
  6. [root@localhost ~]#
  7. [root@localhost ~]# cd Python-3.12.4
  8. [root@localhost Python-3.12.4]# ls
  9. aclocal.m4    config.sub  configure.ac  Grammar  install-sh  LICENSE  Makefile.pre.in  Modules  Parser  PCbuild   pyconfig.h.in  README.rst
  10. config.guess  configure   Doc           Include  Lib         Mac      Misc             Objects  PC      Programs  Python         Tools
  11. [root@localhost Python-3.12.4]#
复制代码
2.4 配置python-3.12.4

  1. [root@localhost Python-3.12.4]#./configure  --prefix=/opt/python3  --enable-optimizations
  2. ......
  3. checking for chown... yes
  4. checking for clock... yes
  5. checking for close_range... no
  6. checking for confstr... yes
  7. checking for copy_file_range... yes
  8. checking for ctermid... yes
  9. checking for dup... yes
  10. checking for dup3... yes
  11. checking for execv... yes
  12. checking for explicit_bzero... yes
  13. checking for explicit_memset... no
  14. checking for faccessat... yes
  15. checking for fchmod... yes
  16. checking for fchmodat... yes
  17. checking for fchown... yes
  18. checking for fchownat... yes
  19. checking for fdopendir... yes
  20. checking for fdwalk... no
  21. checking for fexecve... yes
  22. checking for fork... yes
  23. checking for fork1... no
  24. checking for fpathconf... yes
  25. checking for fstatat... yes
  26. checking for ftime... yes
  27. checking for ftruncate... yes
  28. checking for futimens... yes
  29. checking for futimes... yes
  30. checking for futimesat... yes
  31. checking for gai_strerror... yes
  32. checking for getegid... yes
  33. checking for getentropy... yes
  34. checking for geteuid... yes
  35. checking for getgid... yes
  36. checking for getgrgid... yes
  37. checking for getgrgid_r... yes
  38. checking for getgrnam_r... yes
  39. checking for getgrouplist... yes
  40. checking for getgroups... yes
  41. checking for gethostname... yes
  42. checking for getitimer... yes
  43. checking for getloadavg... yes
  44. checking for getlogin... yes
  45. checking for getpeername... yes
  46. checking for getpgid... yes
  47. checking for getpid... yes
  48. checking for getppid... yes
  49. checking for getpriority... yes
  50. checking for _getpty... no
  51. checking for getpwent... yes
  52. checking for getpwnam_r... yes
  53. checking for getpwuid... yes
  54. checking for getpwuid_r... yes
  55. checking for getresgid... yes
  56. checking for getresuid... yes
  57. checking for getrusage... yes
  58. checking for getsid... yes
  59. checking for getspent... yes
  60. checking for getspnam... yes
  61. checking for getuid... yes
  62. checking for getwd... yes
  63. checking for if_nameindex... yes
  64. checking for initgroups... yes
  65. checking for kill... yes
  66. checking for killpg... yes
  67. checking for lchown... yes
  68. checking for linkat... yes
  69. checking for lockf... yes
  70. checking for lstat... yes
  71. checking for lutimes... yes
  72. checking for madvise... yes
  73. checking for mbrtowc... yes
  74. checking for memrchr... yes
  75. checking for mkdirat... yes
  76. checking for mkfifo... yes
  77. checking for mkfifoat... yes
  78. checking for mknod... yes
  79. checking for mknodat... yes
  80. checking for mktime... yes
  81. checking for mmap... yes
  82. checking for mremap... yes
  83. checking for nice... yes
  84. checking for openat... yes
  85. checking for opendir... yes
  86. checking for pathconf... yes
  87. checking for pause... yes
  88. checking for pipe... yes
  89. checking for pipe2... yes
  90. checking for plock... no
  91. checking for poll... yes
  92. checking for posix_fadvise... yes
  93. checking for posix_fallocate... yes
  94. checking for posix_spawn... yes
  95. checking for posix_spawnp... yes
  96. checking for pread... yes
  97. checking for preadv... yes
  98. checking for preadv2... yes
  99. checking for pthread_condattr_setclock... yes
  100. checking for pthread_init... no
  101. checking for pthread_kill... yes
  102. checking for pwrite... yes
  103. checking for pwritev... yes
  104. checking for pwritev2... yes
  105. checking for readlink... yes
  106. checking for readlinkat... yes
  107. checking for readv... yes
  108. checking for realpath... yes
  109. checking for renameat... yes
  110. checking for rtpSpawn... no
  111. checking for sched_get_priority_max... yes
  112. checking for sched_rr_get_interval... yes
  113. checking for sched_setaffinity... yes
  114. checking for sched_setparam... yes
  115. checking for sched_setscheduler... yes
  116. checking for sem_clockwait... no
  117. checking for sem_getvalue... yes
  118. checking for sem_open... yes
  119. checking for sem_timedwait... yes
  120. checking for sem_unlink... yes
  121. checking for sendfile... yes
  122. checking for setegid... yes
  123. checking for seteuid... yes
  124. checking for setgid... yes
  125. checking for sethostname... yes
  126. checking for setitimer... yes
  127. checking for setlocale... yes
  128. checking for setpgid... yes
  129. checking for setpgrp... yes
  130. checking for setpriority... yes
  131. checking for setregid... yes
  132. checking for setresgid... yes
  133. checking for setresuid... yes
  134. checking for setreuid... yes
  135. checking for setsid... yes
  136. checking for setuid... yes
  137. checking for setvbuf... yes
  138. checking for shutdown... yes
  139. checking for sigaction... yes
  140. checking for sigaltstack... yes
  141. checking for sigfillset... yes
  142. checking for siginterrupt... yes
  143. checking for sigpending... yes
  144. checking for sigrelse... yes
  145. checking for sigtimedwait... yes
  146. checking for sigwait... yes
  147. checking for sigwaitinfo... yes
  148. checking for snprintf... yes
  149. checking for splice... yes
  150. checking for strftime... yes
  151. checking for strlcpy... no
  152. checking for strsignal... yes
  153. checking for symlinkat... yes
  154. checking for sync... yes
  155. checking for sysconf... yes
  156. checking for system... yes
  157. checking for tcgetpgrp... yes
  158. checking for tcsetpgrp... yes
  159. checking for tempnam... yes
  160. checking for timegm... yes
  161. checking for times... yes
  162. checking for tmpfile... yes
  163. checking for tmpnam... yes
  164. checking for tmpnam_r... yes
  165. checking for truncate... yes
  166. checking for ttyname... yes
  167. checking for umask... yes
  168. checking for uname... yes
  169. checking for unlinkat... yes
  170. checking for utimensat... yes
  171. checking for utimes... yes
  172. checking for vfork... yes
  173. checking for wait... yes
  174. checking for wait3... yes
  175. checking for wait4... yes
  176. checking for waitid... yes
  177. checking for waitpid... yes
  178. checking for wcscoll... yes
  179. checking for wcsftime... yes
  180. checking for wcsxfrm... yes
  181. checking for wmemcmp... yes
  182. checking for writev... yes
  183. checking for gcc -pthread options needed to detect all undeclared functions... none needed
  184. checking whether dirfd is declared... yes
  185. checking for chroot... yes
  186. checking for link... yes
  187. checking for symlink... yes
  188. checking for fchdir... yes
  189. checking for fsync... yes
  190. checking for fdatasync... yes
  191. checking for epoll_create... yes
  192. checking for epoll_create1... yes
  193. checking for kqueue... no
  194. checking for prlimit... yes
  195. checking for _dyld_shared_cache_contains_path... no
  196. checking for memfd_create... yes
  197. checking for eventfd... yes
  198. checking for ctermid_r... no
  199. checking for flock declaration... yes
  200. checking for flock... yes
  201. checking for getpagesize... yes
  202. checking for broken unsetenv... no
  203. checking for true... true
  204. checking for inet_aton in -lc... yes
  205. checking for chflags... no
  206. checking for lchflags... no
  207. checking for zlib >= 1.2.0... yes
  208. checking for bzip2... yes
  209. checking for liblzma... yes
  210. checking for hstrerror... yes
  211. checking for getservbyname... yes
  212. checking for getservbyport... yes
  213. checking for gethostbyname... yes
  214. checking for gethostbyaddr... yes
  215. checking for getprotobyname... yes
  216. checking for inet_aton... yes
  217. checking for inet_ntoa... yes
  218. checking for inet_pton... yes
  219. checking for getpeername... (cached) yes
  220. checking for getsockname... yes
  221. checking for accept... yes
  222. checking for bind... yes
  223. checking for connect... yes
  224. checking for listen... yes
  225. checking for recvfrom... yes
  226. checking for sendto... yes
  227. checking for setsockopt... yes
  228. checking for socket... yes
  229. checking for setgroups... yes
  230. checking for openpty... no
  231. checking for openpty in -lutil... yes
  232. checking for library containing login_tty... none required
  233. checking for forkpty... yes
  234. checking for fseek64... no
  235. checking for fseeko... yes
  236. checking for fstatvfs... yes
  237. checking for ftell64... no
  238. checking for ftello... yes
  239. checking for statvfs... yes
  240. checking for dup2... yes
  241. checking for getpgrp... yes
  242. checking for setpgrp... (cached) yes
  243. checking for setns... yes
  244. checking for unshare... yes
  245. checking for libxcrypt >= 3.1.1... yes
  246. checking for crypt or crypt_r... yes
  247. checking for clock_gettime... yes
  248. checking for clock_getres... yes
  249. checking for clock_settime... yes
  250. checking for clock_nanosleep... yes
  251. checking for nanosleep... yes
  252. checking for major, minor, and makedev... yes
  253. checking for getaddrinfo... yes
  254. checking getaddrinfo bug... no
  255. checking for getnameinfo... yes
  256. checking whether struct tm is in sys/time.h or time.h... time.h
  257. checking for struct tm.tm_zone... yes
  258. checking for struct stat.st_rdev... yes
  259. checking for struct stat.st_blksize... yes
  260. checking for struct stat.st_flags... no
  261. checking for struct stat.st_gen... no
  262. checking for struct stat.st_birthtime... no
  263. checking for struct stat.st_blocks... yes
  264. checking for struct passwd.pw_gecos... yes
  265. checking for struct passwd.pw_passwd... yes
  266. checking for siginfo_t.si_band... yes
  267. checking for time.h that defines altzone... no
  268. checking for addrinfo... yes
  269. checking for sockaddr_storage... yes
  270. checking for sockaddr_alg... yes
  271. checking for an ANSI C-conforming const... yes
  272. checking for working signed char... yes
  273. checking for prototypes... yes
  274. checking for socketpair... yes
  275. checking if sockaddr has sa_len member... no
  276. checking for gethostbyname_r... yes
  277. checking gethostbyname_r with 6 args... yes
  278. checking for __fpu_control... yes
  279. checking for --with-libm=STRING... default LIBM="-lm"
  280. checking for --with-libc=STRING... default LIBC=""
  281. checking for x64 gcc inline assembler... yes
  282. checking whether float word ordering is bigendian... no
  283. checking whether we can use gcc inline assembler to get and set x87 control word... yes
  284. checking whether we can use gcc inline assembler to get and set mc68881 fpcr... no
  285. checking for x87-style double rounding... no
  286. checking for acosh... yes
  287. checking for asinh... yes
  288. checking for atanh... yes
  289. checking for erf... yes
  290. checking for erfc... yes
  291. checking for expm1... yes
  292. checking for log1p... yes
  293. checking for log2... yes
  294. checking whether POSIX semaphores are enabled... yes
  295. checking for broken sem_getvalue... no
  296. checking whether RTLD_LAZY is declared... yes
  297. checking whether RTLD_NOW is declared... yes
  298. checking whether RTLD_GLOBAL is declared... yes
  299. checking whether RTLD_LOCAL is declared... yes
  300. checking whether RTLD_NODELETE is declared... yes
  301. checking whether RTLD_NOLOAD is declared... yes
  302. checking whether RTLD_DEEPBIND is declared... yes
  303. checking whether RTLD_MEMBER is declared... no
  304. checking digit size for Python's longs... no value specified
  305. checking for wchar.h... (cached) yes
  306. checking size of wchar_t... 4
  307. checking whether wchar_t is signed... yes
  308. checking whether wchar_t is usable... no
  309. checking whether byte ordering is bigendian... no
  310. checking ABIFLAGS...
  311. checking SOABI... cpython-312-x86_64-linux-gnu
  312. checking LDVERSION... $(VERSION)$(ABIFLAGS)
  313. checking for --with-platlibdir... no
  314. checking for --with-wheel-pkg-dir... no
  315. checking whether right shift extends the sign bit... yes
  316. checking for getc_unlocked() and friends... yes
  317. checking for readline... yes
  318. checking how to link readline... readline (CFLAGS: -I/usr/include/readline -D_DEFAULT_SOURCE , LIBS: -lreadline )
  319. checking whether rl_completion_append_character is declared... yes
  320. checking whether rl_completion_suppress_append is declared... yes
  321. checking for rl_pre_input_hook in -lreadline... yes
  322. checking for rl_completion_display_matches_hook in -lreadline... yes
  323. checking for rl_resize_terminal in -lreadline... yes
  324. checking for rl_completion_matches in -lreadline... yes
  325. checking whether rl_catch_signals is declared... yes
  326. checking for append_history in -lreadline... yes
  327. checking for rl_compdisp_func_t... yes
  328. checking for broken nice()... no
  329. checking for broken poll()... no
  330. checking for working tzset()... yes
  331. checking for tv_nsec in struct stat... yes
  332. checking for tv_nsec2 in struct stat... no
  333. checking for curses.h... yes
  334. checking for ncurses.h... yes
  335. checking for ncursesw... yes
  336. checking curses module flags... ncursesw (CFLAGS: -D_DEFAULT_SOURCE , LIBS: -lncursesw -ltinfo )
  337. checking for panel.h... yes
  338. checking for panelw... yes
  339. checking panel flags... panelw (CFLAGS: -D_DEFAULT_SOURCE , LIBS: -lpanelw )
  340. checking for term.h... yes
  341. checking whether mvwdelch is an expression... yes
  342. checking whether WINDOW has _flags... yes
  343. checking for curses function is_pad... yes
  344. checking for curses function is_term_resized... yes
  345. checking for curses function resize_term... yes
  346. checking for curses function resizeterm... yes
  347. checking for curses function immedok... yes
  348. checking for curses function syncok... yes
  349. checking for curses function wchgat... yes
  350. checking for curses function filter... yes
  351. checking for curses function has_key... yes
  352. checking for curses function typeahead... yes
  353. checking for curses function use_env... yes
  354. configure: checking for device files
  355. checking for /dev/ptmx... yes
  356. checking for /dev/ptc... no
  357. checking for socklen_t... yes
  358. checking for broken mbstowcs... no
  359. checking for --with-computed-gotos... no value specified
  360. checking whether gcc -pthread supports computed gotos... yes
  361. checking for build directories... done
  362. checking for -O2... yes
  363. checking for glibc _FORTIFY_SOURCE/memmove bug... no
  364. checking for gcc ipa-pure-const bug... no
  365. checking for stdatomic.h... yes
  366. checking for builtin __atomic_load_n and __atomic_store_n functions... yes
  367. checking for ensurepip... upgrade
  368. checking if the dirent structure of a d_type field... yes
  369. checking for the Linux getrandom() syscall... yes
  370. checking for the getrandom() function... yes
  371. checking for library containing shm_open... -lrt
  372. checking for shm_open... yes
  373. checking for shm_unlink... yes
  374. checking for pkg-config... /bin/pkg-config
  375. checking whether compiling and linking against OpenSSL works... yes
  376. checking for --with-openssl-rpath...
  377. checking whether OpenSSL provides required ssl module APIs... yes
  378. checking whether OpenSSL provides required hashlib module APIs... yes
  379. checking for --with-ssl-default-suites... python
  380. checking for --with-builtin-hashlib-hashes... md5,sha1,sha2,sha3,blake2
  381. checking for libb2... no
  382. checking for --disable-test-modules... yes
  383. checking for stdlib extension module _multiprocessing... yes
  384. checking for stdlib extension module _posixshmem... yes
  385. checking for stdlib extension module fcntl... yes
  386. checking for stdlib extension module mmap... yes
  387. checking for stdlib extension module _socket... yes
  388. checking for stdlib extension module grp... yes
  389. checking for stdlib extension module ossaudiodev... yes
  390. checking for stdlib extension module pwd... yes
  391. checking for stdlib extension module resource... yes
  392. checking for stdlib extension module _scproxy... n/a
  393. checking for stdlib extension module spwd... yes
  394. checking for stdlib extension module syslog... yes
  395. checking for stdlib extension module termios... yes
  396. checking for stdlib extension module pyexpat... yes
  397. checking for stdlib extension module _elementtree... yes
  398. checking for stdlib extension module _md5... yes
  399. checking for stdlib extension module _sha1... yes
  400. checking for stdlib extension module _sha2... yes
  401. checking for stdlib extension module _sha3... yes
  402. checking for stdlib extension module _blake2... yes
  403. checking for stdlib extension module _crypt... yes
  404. checking for stdlib extension module _ctypes... yes
  405. checking for stdlib extension module _curses... yes
  406. checking for stdlib extension module _curses_panel... yes
  407. checking for stdlib extension module _decimal... yes
  408. checking for stdlib extension module _dbm... missing
  409. checking for stdlib extension module _gdbm... missing
  410. checking for stdlib extension module nis... missing
  411. checking for stdlib extension module readline... yes
  412. checking for stdlib extension module _sqlite3... yes
  413. checking for stdlib extension module _tkinter... yes
  414. checking for stdlib extension module _uuid... missing
  415. checking for stdlib extension module zlib... yes
  416. checking for stdlib extension module _bz2... yes
  417. checking for stdlib extension module _lzma... yes
  418. checking for stdlib extension module _ssl... yes
  419. checking for stdlib extension module _hashlib... yes
  420. checking for stdlib extension module _testcapi... yes
  421. checking for stdlib extension module _testclinic... yes
  422. checking for stdlib extension module _testinternalcapi... yes
  423. checking for stdlib extension module _testbuffer... yes
  424. checking for stdlib extension module _testimportmultiple... yes
  425. checking for stdlib extension module _testmultiphase... yes
  426. checking for stdlib extension module xxsubtype... yes
  427. checking for stdlib extension module _xxtestfuzz... yes
  428. checking for stdlib extension module _ctypes_test... yes
  429. checking for stdlib extension module xxlimited... yes
  430. checking for stdlib extension module xxlimited_35... yes
  431. configure: creating ./config.status
  432. config.status: creating Makefile.pre
  433. config.status: creating Misc/python.pc
  434. config.status: creating Misc/python-embed.pc
  435. config.status: creating Misc/python-config.sh
  436. config.status: creating Modules/Setup.bootstrap
  437. config.status: creating Modules/Setup.stdlib
  438. config.status: creating Modules/ld_so_aix
  439. config.status: creating pyconfig.h
  440. configure: creating Modules/Setup.local
  441. configure: creating Makefile
  442. [root@localhost Python-3.12.4]#
复制代码
2.5 编译安装

  1. [root@localhost Python-3.12.4]#  make && make install
  2. if test "no-framework" = "no-framework" ; then \
  3.         /bin/install -c python /opt/python3/bin/python3.12; \
  4. else \
  5.         /bin/install -c -s Mac/pythonw /opt/python3/bin/python3.12; \
  6. fi
  7. if test "3.12" != "3.12"; then \
  8.         if test -f /opt/python3/bin/python3.12 -o -h /opt/python3/bin/python3.12; \
  9.         then rm -f /opt/python3/bin/python3.12; \
  10.         fi; \
  11.         (cd /opt/python3/bin; ln python3.12 python3.12); \
  12. fi
  13. if test "x" != "x" ; then \
  14.         rm -f /opt/python3/bin/python3.12-32; \
  15.         lipo  \
  16.                 -output /opt/python3/bin/python3.12-32 \
  17.                 /opt/python3/bin/python3.12; \
  18. fi
  19. if test "x" != "x" ; then \
  20.         rm -f /opt/python3/bin/python3.12-intel64; \
  21.         lipo  \
  22.                 -output /opt/python3/bin/python3.12-intel64 \
  23.                 /opt/python3/bin/python3.12; \
  24. fi
  25. # Install macOS debug information (if available)
  26. if test -d "python.dSYM"; then \
  27.         echo  /opt/python3/bin/python3.12; \
  28.          /opt/python3/bin/python3.12; \
  29. fi
  30. if test "no-framework" = "no-framework" ; then \
  31.         if test -d "libpython3.12.a.dSYM"; then \
  32.                 echo  /opt/python3/lib/libpython3.12.a; \
  33.                  /opt/python3/lib/libpython3.12.a; \
  34.         fi \
  35. else \
  36.         if test -d "libpython3.12.a.dSYM"; then \
  37.                 echo  /libpython3.12.a; \
  38.        /libpython3.12.a; \
  39.         fi \
  40. fi
  41. Rebuilding with profile guided optimizations:
  42. rm -f profile-clean-stamp
  43. make build_all CFLAGS_NODIST=" -fprofile-use -fprofile-correction" LDFLAGS_NODIST=""
  44. make[1]: 进入目录“/root/Python-3.12.4”
  45. The necessary bits to build these optional modules were not found:
  46. _dbm                  _gdbm                 _uuid
  47. nis
  48. To find the necessary bits, look in configure.ac and config.log.
  49. ......
  50. ......
  51. ......
  52. ......
  53. ......
  54. ......
  55. /bin/install -c -m 755 Modules/_bisect.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_bisect.cpython-312-x86_64-linux-gnu.so
  56. /bin/install -c -m 755 Modules/_contextvars.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_contextvars.cpython-312-x86_64-linux-gnu.so
  57. /bin/install -c -m 755 Modules/_csv.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_csv.cpython-312-x86_64-linux-gnu.so
  58. /bin/install -c -m 755 Modules/_heapq.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_heapq.cpython-312-x86_64-linux-gnu.so
  59. /bin/install -c -m 755 Modules/_json.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_json.cpython-312-x86_64-linux-gnu.so
  60. /bin/install -c -m 755 Modules/_lsprof.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_lsprof.cpython-312-x86_64-linux-gnu.so
  61. /bin/install -c -m 755 Modules/_opcode.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_opcode.cpython-312-x86_64-linux-gnu.so
  62. /bin/install -c -m 755 Modules/_pickle.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_pickle.cpython-312-x86_64-linux-gnu.so
  63. /bin/install -c -m 755 Modules/_queue.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_queue.cpython-312-x86_64-linux-gnu.so
  64. /bin/install -c -m 755 Modules/_random.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_random.cpython-312-x86_64-linux-gnu.so
  65. /bin/install -c -m 755 Modules/_struct.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_struct.cpython-312-x86_64-linux-gnu.so
  66. /bin/install -c -m 755 Modules/_xxsubinterpreters.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_xxsubinterpreters.cpython-312-x86_64-linux-gnu.so
  67. /bin/install -c -m 755 Modules/_xxinterpchannels.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_xxinterpchannels.cpython-312-x86_64-linux-gnu.so
  68. /bin/install -c -m 755 Modules/_zoneinfo.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_zoneinfo.cpython-312-x86_64-linux-gnu.so
  69. /bin/install -c -m 755 Modules/audioop.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/audioop.cpython-312-x86_64-linux-gnu.so
  70. /bin/install -c -m 755 Modules/math.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/math.cpython-312-x86_64-linux-gnu.so
  71. /bin/install -c -m 755 Modules/cmath.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/cmath.cpython-312-x86_64-linux-gnu.so
  72. /bin/install -c -m 755 Modules/_statistics.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_statistics.cpython-312-x86_64-linux-gnu.so
  73. /bin/install -c -m 755 Modules/_datetime.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_datetime.cpython-312-x86_64-linux-gnu.so
  74. /bin/install -c -m 755 Modules/_decimal.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_decimal.cpython-312-x86_64-linux-gnu.so
  75. /bin/install -c -m 755 Modules/binascii.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/binascii.cpython-312-x86_64-linux-gnu.so
  76. /bin/install -c -m 755 Modules/_bz2.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_bz2.cpython-312-x86_64-linux-gnu.so
  77. /bin/install -c -m 755 Modules/_lzma.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_lzma.cpython-312-x86_64-linux-gnu.so
  78. /bin/install -c -m 755 Modules/zlib.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/zlib.cpython-312-x86_64-linux-gnu.so
  79. /bin/install -c -m 755 Modules/readline.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/readline.cpython-312-x86_64-linux-gnu.so
  80. /bin/install -c -m 755 Modules/_md5.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_md5.cpython-312-x86_64-linux-gnu.so
  81. /bin/install -c -m 755 Modules/_sha1.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_sha1.cpython-312-x86_64-linux-gnu.so
  82. /bin/install -c -m 755 Modules/_sha2.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_sha2.cpython-312-x86_64-linux-gnu.so
  83. /bin/install -c -m 755 Modules/_sha3.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_sha3.cpython-312-x86_64-linux-gnu.so
  84. /bin/install -c -m 755 Modules/_blake2.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_blake2.cpython-312-x86_64-linux-gnu.so
  85. /bin/install -c -m 755 Modules/pyexpat.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/pyexpat.cpython-312-x86_64-linux-gnu.so
  86. /bin/install -c -m 755 Modules/_elementtree.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_elementtree.cpython-312-x86_64-linux-gnu.so
  87. /bin/install -c -m 755 Modules/_codecs_cn.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_codecs_cn.cpython-312-x86_64-linux-gnu.so
  88. /bin/install -c -m 755 Modules/_codecs_hk.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_codecs_hk.cpython-312-x86_64-linux-gnu.so
  89. /bin/install -c -m 755 Modules/_codecs_iso2022.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_codecs_iso2022.cpython-312-x86_64-linux-gnu.so
  90. /bin/install -c -m 755 Modules/_codecs_jp.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_codecs_jp.cpython-312-x86_64-linux-gnu.so
  91. /bin/install -c -m 755 Modules/_codecs_kr.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_codecs_kr.cpython-312-x86_64-linux-gnu.so
  92. /bin/install -c -m 755 Modules/_codecs_tw.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_codecs_tw.cpython-312-x86_64-linux-gnu.so
  93. /bin/install -c -m 755 Modules/_multibytecodec.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_multibytecodec.cpython-312-x86_64-linux-gnu.so
  94. /bin/install -c -m 755 Modules/unicodedata.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/unicodedata.cpython-312-x86_64-linux-gnu.so
  95. /bin/install -c -m 755 Modules/_crypt.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_crypt.cpython-312-x86_64-linux-gnu.so
  96. /bin/install -c -m 755 Modules/fcntl.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/fcntl.cpython-312-x86_64-linux-gnu.so
  97. /bin/install -c -m 755 Modules/grp.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/grp.cpython-312-x86_64-linux-gnu.so
  98. /bin/install -c -m 755 Modules/mmap.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/mmap.cpython-312-x86_64-linux-gnu.so
  99. /bin/install -c -m 755 Modules/ossaudiodev.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/ossaudiodev.cpython-312-x86_64-linux-gnu.so
  100. /bin/install -c -m 755 Modules/_posixsubprocess.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_posixsubprocess.cpython-312-x86_64-linux-gnu.so
  101. /bin/install -c -m 755 Modules/resource.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/resource.cpython-312-x86_64-linux-gnu.so
  102. /bin/install -c -m 755 Modules/select.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/select.cpython-312-x86_64-linux-gnu.so
  103. /bin/install -c -m 755 Modules/_socket.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_socket.cpython-312-x86_64-linux-gnu.so
  104. /bin/install -c -m 755 Modules/spwd.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/spwd.cpython-312-x86_64-linux-gnu.so
  105. /bin/install -c -m 755 Modules/syslog.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/syslog.cpython-312-x86_64-linux-gnu.so
  106. /bin/install -c -m 755 Modules/termios.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/termios.cpython-312-x86_64-linux-gnu.so
  107. /bin/install -c -m 755 Modules/_posixshmem.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_posixshmem.cpython-312-x86_64-linux-gnu.so
  108. /bin/install -c -m 755 Modules/_multiprocessing.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_multiprocessing.cpython-312-x86_64-linux-gnu.so
  109. /bin/install -c -m 755 Modules/_ctypes.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_ctypes.cpython-312-x86_64-linux-gnu.so
  110. /bin/install -c -m 755 Modules/_curses.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_curses.cpython-312-x86_64-linux-gnu.so
  111. /bin/install -c -m 755 Modules/_curses_panel.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_curses_panel.cpython-312-x86_64-linux-gnu.so
  112. /bin/install -c -m 755 Modules/_sqlite3.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_sqlite3.cpython-312-x86_64-linux-gnu.so
  113. /bin/install -c -m 755 Modules/_ssl.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_ssl.cpython-312-x86_64-linux-gnu.so
  114. /bin/install -c -m 755 Modules/_hashlib.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_hashlib.cpython-312-x86_64-linux-gnu.so
  115. /bin/install -c -m 755 Modules/_tkinter.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_tkinter.cpython-312-x86_64-linux-gnu.so
  116. /bin/install -c -m 755 Modules/xxsubtype.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/xxsubtype.cpython-312-x86_64-linux-gnu.so
  117. /bin/install -c -m 755 Modules/_xxtestfuzz.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_xxtestfuzz.cpython-312-x86_64-linux-gnu.so
  118. /bin/install -c -m 755 Modules/_testbuffer.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_testbuffer.cpython-312-x86_64-linux-gnu.so
  119. /bin/install -c -m 755 Modules/_testinternalcapi.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_testinternalcapi.cpython-312-x86_64-linux-gnu.so
  120. /bin/install -c -m 755 Modules/_testcapi.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_testcapi.cpython-312-x86_64-linux-gnu.so
  121. /bin/install -c -m 755 Modules/_testclinic.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_testclinic.cpython-312-x86_64-linux-gnu.so
  122. /bin/install -c -m 755 Modules/_testimportmultiple.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_testimportmultiple.cpython-312-x86_64-linux-gnu.so
  123. /bin/install -c -m 755 Modules/_testmultiphase.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_testmultiphase.cpython-312-x86_64-linux-gnu.so
  124. /bin/install -c -m 755 Modules/_testsinglephase.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_testsinglephase.cpython-312-x86_64-linux-gnu.so
  125. /bin/install -c -m 755 Modules/_ctypes_test.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/_ctypes_test.cpython-312-x86_64-linux-gnu.so
  126. /bin/install -c -m 755 Modules/xxlimited.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/xxlimited.cpython-312-x86_64-linux-gnu.so
  127. /bin/install -c -m 755 Modules/xxlimited_35.cpython-312-x86_64-linux-gnu.so /opt/python3/lib/python3.12/lib-dynload/xxlimited_35.cpython-312-x86_64-linux-gnu.so
  128. /bin/install -c -m 644 ./Misc/python.man \
  129.         /opt/python3/share/man/man1/python3.12.1
  130. if test ! -d /opt/python3/lib/pkgconfig; then \
  131.         echo "Creating directory /opt/python3/lib/pkgconfig"; \
  132.         /bin/install -c -d -m 755 /opt/python3/lib/pkgconfig; \
  133. fi
  134. if test -f /opt/python3/bin/python3 -o -h /opt/python3/bin/python3; \
  135. then rm -f /opt/python3/bin/python3; \
  136. else true; \
  137. fi
  138. (cd /opt/python3/bin; ln -s python3.12 python3)
  139. if test "3.12" != "3.12"; then \
  140.         rm -f /opt/python3/bin/python3.12-config; \
  141.         (cd /opt/python3/bin; ln -s python3.12-config python3.12-config); \
  142.         rm -f /opt/python3/lib/pkgconfig/python-3.12.pc; \
  143.         (cd /opt/python3/lib/pkgconfig; ln -s python-3.12.pc python-3.12.pc); \
  144.         rm -f /opt/python3/lib/pkgconfig/python-3.12-embed.pc; \
  145.         (cd /opt/python3/lib/pkgconfig; ln -s python-3.12-embed.pc python-3.12-embed.pc); \
  146. fi
  147. rm -f /opt/python3/bin/python3-config
  148. (cd /opt/python3/bin; ln -s python3.12-config python3-config)
  149. rm -f /opt/python3/lib/pkgconfig/python3.pc
  150. (cd /opt/python3/lib/pkgconfig; ln -s python-3.12.pc python3.pc)
  151. rm -f /opt/python3/lib/pkgconfig/python3-embed.pc
  152. (cd /opt/python3/lib/pkgconfig; ln -s python-3.12-embed.pc python3-embed.pc)
  153. rm -f /opt/python3/bin/idle3
  154. (cd /opt/python3/bin; ln -s idle3.12 idle3)
  155. rm -f /opt/python3/bin/pydoc3
  156. (cd /opt/python3/bin; ln -s pydoc3.12 pydoc3)
  157. rm -f /opt/python3/bin/2to3
  158. (cd /opt/python3/bin; ln -s 2to3-3.12 2to3)
  159. if test "x" != "x" ; then \
  160.         rm -f /opt/python3/bin/python3-32; \
  161.         (cd /opt/python3/bin; ln -s python3.12-32 python3-32) \
  162. fi
  163. if test "x" != "x" ; then \
  164.         rm -f /opt/python3/bin/python3-intel64; \
  165.         (cd /opt/python3/bin; ln -s python3.12-intel64 python3-intel64) \
  166. fi
  167. rm -f /opt/python3/share/man/man1/python3.1
  168. (cd /opt/python3/share/man/man1; ln -s python3.12.1 python3.1)
  169. if test "xupgrade" != "xno"  ; then \
  170.         case upgrade in \
  171.                 upgrade) ensurepip="--upgrade" ;; \
  172.                 install|*) ensurepip="" ;; \
  173.         esac; \
  174.          ./python -E -m ensurepip \
  175.                 $ensurepip --root=/ ; \
  176. fi
  177. Looking in links: /tmp/tmpeykwgd2r
  178. Requirement already satisfied: pip in /opt/python3/lib/python3.12/site-packages (24.0)
  179. WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
复制代码
2.6 配置情况变量使其见效

  1. [root@localhost ~]# echo "export PYTHON_HOME=/opt/python3"  >> /etc/profile
  2. [root@localhost ~]# echo "export PATH=$PYTHON_HOME/bin:$PATH"  >> /etc/profile
  3. [root@localhost ~]# source /etc/profile
复制代码
2.7 检查是否安装乐成

  1. [root@localhost ~]# python3
  2. Python 3.12.4 (main, Jul  4 2024, 09:38:24) [GCC 7.3.0] on linux
  3. Type "help", "copyright", "credits" or "license" for more information.
  4. >>> exit()
  5. [root@localhost ~]# pip3 --version
  6. pip 24.0 from /opt/python3/lib/python3.12/site-packages/pip (python 3.12)
  7. [root@localhost ~]#
复制代码
2.8 编写交互式测试步伐测试

  1. [root@localhost ~]# cat python3-test.py
  2. #!/opt/python3
  3. def add(x, y):
  4.     return x + y
  5. def subtract(x, y):
  6.     return x - y
  7. def multiply(x, y):
  8.     return x * y
  9. def divide(x, y):
  10.     if y != 0:
  11.         return x / y
  12.     else:
  13.         return "除数不能为0"
  14. while True:
  15.     print("选择运算:")
  16.     print("1.加法")
  17.     print("2.减法")
  18.     print("3.乘法")
  19.     print("4.除法")
  20.     print("5.退出")
  21.     choice = input("输入你的选择(1/2/3/4/5): ")
  22.     if choice in ('1', '2', '3', '4'):
  23.         num1 = float(input("输入第一个数字: "))
  24.         num2 = float(input("输入第二个数字: "))
  25.         if choice == '1':
  26.             print("结果是:", add(num1, num2))
  27.         elif choice == '2':
  28.             print("结果是:", subtract(num1, num2))
  29.         elif choice == '3':
  30.             print("结果是:", multiply(num1, num2))
  31.         elif choice == '4':
  32.             print("结果是:", divide(num1, num2))
  33.     elif choice == '5':
  34.         print("退出程序。")
  35.         break
  36.     else:
  37.         print("无效输入")
  38. [root@localhost ~]# python3 python3-test.py
  39. 选择运算:
  40. 1.加法
  41. 2.减法
  42. 3.乘法
  43. 4.除法
  44. 5.退出
  45. 输入你的选择(1/2/3/4/5): 1
  46. 输入第一个数字: 3
  47. 输入第二个数字: 65
  48. 结果是: 68.0
  49. 选择运算:
  50. 1.加法
  51. 2.减法
  52. 3.乘法
  53. 4.除法
  54. 5.退出
  55. 输入你的选择(1/2/3/4/5): 5
  56. 退出程序。
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

没腿的鸟

金牌会员
这个人很懒什么都没写!

标签云

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