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

avatar
作者
猴君
阅读量:0

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

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

一 系统环境

[root@localhost ~]# nkvers ############## Kylin Linux Version ################# Release: Kylin Linux Advanced Server release V10 (Lance)  Kernel: 4.19.90-52.22.v2207.ky10.x86_64  Build: Kylin Linux Advanced Server release V10 (SP3) /(Lance)-x86_64-Build23/20230324 ################################################# 

二 安装python3.12.4

2.1 安装编译需要的依赖包

如果网络可以正常连接互联网,直接执行,如果不能访问外网,需要将ISO镜像文件配置成本地yum源!! [root@localhost ~]# yum install libffi-devel tcl-devel tk-devel perl-CPAN openssl-devel readline-devel sqlite-devel openssl -y 

2.2 下载官网目前最新的python源码包

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

[root@localhost ~]# ls anaconda-ks.cfg  initial-setup-ks.cfg  Python-3.12.4.tar.xz  test.py [root@localhost ~]#  [root@localhost ~]#  [root@localhost ~]# tar xf Python-3.12.4.tar.xz  [root@localhost ~]#  [root@localhost ~]# cd Python-3.12.4 [root@localhost Python-3.12.4]# ls aclocal.m4    config.sub  configure.ac  Grammar  install-sh  LICENSE  Makefile.pre.in  Modules  Parser  PCbuild   pyconfig.h.in  README.rst config.guess  configure   Doc           Include  Lib         Mac      Misc             Objects  PC      Programs  Python         Tools [root@localhost Python-3.12.4]#  

2.4 配置python-3.12.4

[root@localhost Python-3.12.4]#./configure  --prefix=/opt/python3  --enable-optimizations  ...... checking for chown... yes checking for clock... yes checking for close_range... no checking for confstr... yes checking for copy_file_range... yes checking for ctermid... yes checking for dup... yes checking for dup3... yes checking for execv... yes checking for explicit_bzero... yes checking for explicit_memset... no checking for faccessat... yes checking for fchmod... yes checking for fchmodat... yes checking for fchown... yes checking for fchownat... yes checking for fdopendir... yes checking for fdwalk... no checking for fexecve... yes checking for fork... yes checking for fork1... no checking for fpathconf... yes checking for fstatat... yes checking for ftime... yes checking for ftruncate... yes checking for futimens... yes checking for futimes... yes checking for futimesat... yes checking for gai_strerror... yes checking for getegid... yes checking for getentropy... yes checking for geteuid... yes checking for getgid... yes checking for getgrgid... yes checking for getgrgid_r... yes checking for getgrnam_r... yes checking for getgrouplist... yes checking for getgroups... yes checking for gethostname... yes checking for getitimer... yes checking for getloadavg... yes checking for getlogin... yes checking for getpeername... yes checking for getpgid... yes checking for getpid... yes checking for getppid... yes checking for getpriority... yes checking for _getpty... no checking for getpwent... yes checking for getpwnam_r... yes checking for getpwuid... yes checking for getpwuid_r... yes checking for getresgid... yes checking for getresuid... yes checking for getrusage... yes checking for getsid... yes checking for getspent... yes checking for getspnam... yes checking for getuid... yes checking for getwd... yes checking for if_nameindex... yes checking for initgroups... yes checking for kill... yes checking for killpg... yes checking for lchown... yes checking for linkat... yes checking for lockf... yes checking for lstat... yes checking for lutimes... yes checking for madvise... yes checking for mbrtowc... yes checking for memrchr... yes checking for mkdirat... yes checking for mkfifo... yes checking for mkfifoat... yes checking for mknod... yes checking for mknodat... yes checking for mktime... yes checking for mmap... yes checking for mremap... yes checking for nice... yes checking for openat... yes checking for opendir... yes checking for pathconf... yes checking for pause... yes checking for pipe... yes checking for pipe2... yes checking for plock... no checking for poll... yes checking for posix_fadvise... yes checking for posix_fallocate... yes checking for posix_spawn... yes checking for posix_spawnp... yes checking for pread... yes checking for preadv... yes checking for preadv2... yes checking for pthread_condattr_setclock... yes checking for pthread_init... no checking for pthread_kill... yes checking for pwrite... yes checking for pwritev... yes checking for pwritev2... yes checking for readlink... yes checking for readlinkat... yes checking for readv... yes checking for realpath... yes checking for renameat... yes checking for rtpSpawn... no checking for sched_get_priority_max... yes checking for sched_rr_get_interval... yes checking for sched_setaffinity... yes checking for sched_setparam... yes checking for sched_setscheduler... yes checking for sem_clockwait... no checking for sem_getvalue... yes checking for sem_open... yes checking for sem_timedwait... yes checking for sem_unlink... yes checking for sendfile... yes checking for setegid... yes checking for seteuid... yes checking for setgid... yes checking for sethostname... yes checking for setitimer... yes checking for setlocale... yes checking for setpgid... yes checking for setpgrp... yes checking for setpriority... yes checking for setregid... yes checking for setresgid... yes checking for setresuid... yes checking for setreuid... yes checking for setsid... yes checking for setuid... yes checking for setvbuf... yes checking for shutdown... yes checking for sigaction... yes checking for sigaltstack... yes checking for sigfillset... yes checking for siginterrupt... yes checking for sigpending... yes checking for sigrelse... yes checking for sigtimedwait... yes checking for sigwait... yes checking for sigwaitinfo... yes checking for snprintf... yes checking for splice... yes checking for strftime... yes checking for strlcpy... no checking for strsignal... yes checking for symlinkat... yes checking for sync... yes checking for sysconf... yes checking for system... yes checking for tcgetpgrp... yes checking for tcsetpgrp... yes checking for tempnam... yes checking for timegm... yes checking for times... yes checking for tmpfile... yes checking for tmpnam... yes checking for tmpnam_r... yes checking for truncate... yes checking for ttyname... yes checking for umask... yes checking for uname... yes checking for unlinkat... yes checking for utimensat... yes checking for utimes... yes checking for vfork... yes checking for wait... yes checking for wait3... yes checking for wait4... yes checking for waitid... yes checking for waitpid... yes checking for wcscoll... yes checking for wcsftime... yes checking for wcsxfrm... yes checking for wmemcmp... yes checking for writev... yes checking for gcc -pthread options needed to detect all undeclared functions... none needed checking whether dirfd is declared... yes checking for chroot... yes checking for link... yes checking for symlink... yes checking for fchdir... yes checking for fsync... yes checking for fdatasync... yes checking for epoll_create... yes checking for epoll_create1... yes checking for kqueue... no checking for prlimit... yes checking for _dyld_shared_cache_contains_path... no checking for memfd_create... yes checking for eventfd... yes checking for ctermid_r... no checking for flock declaration... yes checking for flock... yes checking for getpagesize... yes checking for broken unsetenv... no checking for true... true checking for inet_aton in -lc... yes checking for chflags... no checking for lchflags... no checking for zlib >= 1.2.0... yes checking for bzip2... yes checking for liblzma... yes checking for hstrerror... yes checking for getservbyname... yes checking for getservbyport... yes checking for gethostbyname... yes checking for gethostbyaddr... yes checking for getprotobyname... yes checking for inet_aton... yes checking for inet_ntoa... yes checking for inet_pton... yes checking for getpeername... (cached) yes checking for getsockname... yes checking for accept... yes checking for bind... yes checking for connect... yes checking for listen... yes checking for recvfrom... yes checking for sendto... yes checking for setsockopt... yes checking for socket... yes checking for setgroups... yes checking for openpty... no checking for openpty in -lutil... yes checking for library containing login_tty... none required checking for forkpty... yes checking for fseek64... no checking for fseeko... yes checking for fstatvfs... yes checking for ftell64... no checking for ftello... yes checking for statvfs... yes checking for dup2... yes checking for getpgrp... yes checking for setpgrp... (cached) yes checking for setns... yes checking for unshare... yes checking for libxcrypt >= 3.1.1... yes checking for crypt or crypt_r... yes checking for clock_gettime... yes checking for clock_getres... yes checking for clock_settime... yes checking for clock_nanosleep... yes checking for nanosleep... yes checking for major, minor, and makedev... yes checking for getaddrinfo... yes checking getaddrinfo bug... no checking for getnameinfo... yes checking whether struct tm is in sys/time.h or time.h... time.h checking for struct tm.tm_zone... yes checking for struct stat.st_rdev... yes checking for struct stat.st_blksize... yes checking for struct stat.st_flags... no checking for struct stat.st_gen... no checking for struct stat.st_birthtime... no checking for struct stat.st_blocks... yes checking for struct passwd.pw_gecos... yes checking for struct passwd.pw_passwd... yes checking for siginfo_t.si_band... yes checking for time.h that defines altzone... no checking for addrinfo... yes checking for sockaddr_storage... yes checking for sockaddr_alg... yes checking for an ANSI C-conforming const... yes checking for working signed char... yes checking for prototypes... yes checking for socketpair... yes checking if sockaddr has sa_len member... no checking for gethostbyname_r... yes checking gethostbyname_r with 6 args... yes checking for __fpu_control... yes checking for --with-libm=STRING... default LIBM="-lm" checking for --with-libc=STRING... default LIBC="" checking for x64 gcc inline assembler... yes checking whether float word ordering is bigendian... no checking whether we can use gcc inline assembler to get and set x87 control word... yes checking whether we can use gcc inline assembler to get and set mc68881 fpcr... no checking for x87-style double rounding... no checking for acosh... yes checking for asinh... yes checking for atanh... yes checking for erf... yes checking for erfc... yes checking for expm1... yes checking for log1p... yes checking for log2... yes checking whether POSIX semaphores are enabled... yes checking for broken sem_getvalue... no checking whether RTLD_LAZY is declared... yes checking whether RTLD_NOW is declared... yes checking whether RTLD_GLOBAL is declared... yes checking whether RTLD_LOCAL is declared... yes checking whether RTLD_NODELETE is declared... yes checking whether RTLD_NOLOAD is declared... yes checking whether RTLD_DEEPBIND is declared... yes checking whether RTLD_MEMBER is declared... no checking digit size for Python's longs... no value specified checking for wchar.h... (cached) yes checking size of wchar_t... 4 checking whether wchar_t is signed... yes checking whether wchar_t is usable... no checking whether byte ordering is bigendian... no checking ABIFLAGS...  checking SOABI... cpython-312-x86_64-linux-gnu checking LDVERSION... $(VERSION)$(ABIFLAGS) checking for --with-platlibdir... no checking for --with-wheel-pkg-dir... no checking whether right shift extends the sign bit... yes checking for getc_unlocked() and friends... yes checking for readline... yes checking how to link readline... readline (CFLAGS: -I/usr/include/readline -D_DEFAULT_SOURCE , LIBS: -lreadline ) checking whether rl_completion_append_character is declared... yes checking whether rl_completion_suppress_append is declared... yes checking for rl_pre_input_hook in -lreadline... yes checking for rl_completion_display_matches_hook in -lreadline... yes checking for rl_resize_terminal in -lreadline... yes checking for rl_completion_matches in -lreadline... yes checking whether rl_catch_signals is declared... yes checking for append_history in -lreadline... yes checking for rl_compdisp_func_t... yes checking for broken nice()... no checking for broken poll()... no checking for working tzset()... yes checking for tv_nsec in struct stat... yes checking for tv_nsec2 in struct stat... no checking for curses.h... yes checking for ncurses.h... yes checking for ncursesw... yes checking curses module flags... ncursesw (CFLAGS: -D_DEFAULT_SOURCE , LIBS: -lncursesw -ltinfo ) checking for panel.h... yes checking for panelw... yes checking panel flags... panelw (CFLAGS: -D_DEFAULT_SOURCE , LIBS: -lpanelw ) checking for term.h... yes checking whether mvwdelch is an expression... yes checking whether WINDOW has _flags... yes checking for curses function is_pad... yes checking for curses function is_term_resized... yes checking for curses function resize_term... yes checking for curses function resizeterm... yes checking for curses function immedok... yes checking for curses function syncok... yes checking for curses function wchgat... yes checking for curses function filter... yes checking for curses function has_key... yes checking for curses function typeahead... yes checking for curses function use_env... yes configure: checking for device files checking for /dev/ptmx... yes checking for /dev/ptc... no checking for socklen_t... yes checking for broken mbstowcs... no checking for --with-computed-gotos... no value specified checking whether gcc -pthread supports computed gotos... yes checking for build directories... done checking for -O2... yes checking for glibc _FORTIFY_SOURCE/memmove bug... no checking for gcc ipa-pure-const bug... no checking for stdatomic.h... yes checking for builtin __atomic_load_n and __atomic_store_n functions... yes checking for ensurepip... upgrade checking if the dirent structure of a d_type field... yes checking for the Linux getrandom() syscall... yes checking for the getrandom() function... yes checking for library containing shm_open... -lrt checking for shm_open... yes checking for shm_unlink... yes checking for pkg-config... /bin/pkg-config checking whether compiling and linking against OpenSSL works... yes checking for --with-openssl-rpath...  checking whether OpenSSL provides required ssl module APIs... yes checking whether OpenSSL provides required hashlib module APIs... yes checking for --with-ssl-default-suites... python checking for --with-builtin-hashlib-hashes... md5,sha1,sha2,sha3,blake2 checking for libb2... no checking for --disable-test-modules... yes checking for stdlib extension module _multiprocessing... yes checking for stdlib extension module _posixshmem... yes checking for stdlib extension module fcntl... yes checking for stdlib extension module mmap... yes checking for stdlib extension module _socket... yes checking for stdlib extension module grp... yes checking for stdlib extension module ossaudiodev... yes checking for stdlib extension module pwd... yes checking for stdlib extension module resource... yes checking for stdlib extension module _scproxy... n/a checking for stdlib extension module spwd... yes checking for stdlib extension module syslog... yes checking for stdlib extension module termios... yes checking for stdlib extension module pyexpat... yes checking for stdlib extension module _elementtree... yes checking for stdlib extension module _md5... yes checking for stdlib extension module _sha1... yes checking for stdlib extension module _sha2... yes checking for stdlib extension module _sha3... yes checking for stdlib extension module _blake2... yes checking for stdlib extension module _crypt... yes checking for stdlib extension module _ctypes... yes checking for stdlib extension module _curses... yes checking for stdlib extension module _curses_panel... yes checking for stdlib extension module _decimal... yes checking for stdlib extension module _dbm... missing checking for stdlib extension module _gdbm... missing checking for stdlib extension module nis... missing checking for stdlib extension module readline... yes checking for stdlib extension module _sqlite3... yes checking for stdlib extension module _tkinter... yes checking for stdlib extension module _uuid... missing checking for stdlib extension module zlib... yes checking for stdlib extension module _bz2... yes checking for stdlib extension module _lzma... yes checking for stdlib extension module _ssl... yes checking for stdlib extension module _hashlib... yes checking for stdlib extension module _testcapi... yes checking for stdlib extension module _testclinic... yes checking for stdlib extension module _testinternalcapi... yes checking for stdlib extension module _testbuffer... yes checking for stdlib extension module _testimportmultiple... yes checking for stdlib extension module _testmultiphase... yes checking for stdlib extension module xxsubtype... yes checking for stdlib extension module _xxtestfuzz... yes checking for stdlib extension module _ctypes_test... yes checking for stdlib extension module xxlimited... yes checking for stdlib extension module xxlimited_35... yes 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 [root@localhost Python-3.12.4]#  

2.5 编译安装

[root@localhost Python-3.12.4]#  make && make install if test "no-framework" = "no-framework" ; then \         /bin/install -c python /opt/python3/bin/python3.12; \ else \         /bin/install -c -s Mac/pythonw /opt/python3/bin/python3.12; \ fi if test "3.12" != "3.12"; then \         if test -f /opt/python3/bin/python3.12 -o -h /opt/python3/bin/python3.12; \         then rm -f /opt/python3/bin/python3.12; \         fi; \         (cd /opt/python3/bin; ln python3.12 python3.12); \ fi if test "x" != "x" ; then \         rm -f /opt/python3/bin/python3.12-32; \         lipo  \                 -output /opt/python3/bin/python3.12-32 \                 /opt/python3/bin/python3.12; \ fi if test "x" != "x" ; then \         rm -f /opt/python3/bin/python3.12-intel64; \         lipo  \                 -output /opt/python3/bin/python3.12-intel64 \                 /opt/python3/bin/python3.12; \ fi # Install macOS debug information (if available) if test -d "python.dSYM"; then \         echo  /opt/python3/bin/python3.12; \          /opt/python3/bin/python3.12; \ fi if test "no-framework" = "no-framework" ; then \         if test -d "libpython3.12.a.dSYM"; then \                 echo  /opt/python3/lib/libpython3.12.a; \                  /opt/python3/lib/libpython3.12.a; \         fi \ else \         if test -d "libpython3.12.a.dSYM"; then \                 echo  /libpython3.12.a; \        /libpython3.12.a; \         fi \ fi Rebuilding with profile guided optimizations: rm -f profile-clean-stamp make build_all CFLAGS_NODIST=" -fprofile-use -fprofile-correction" LDFLAGS_NODIST="" make[1]: 进入目录“/root/Python-3.12.4” The necessary bits to build these optional modules were not found: _dbm                  _gdbm                 _uuid nis To find the necessary bits, look in configure.ac and config.log. ...... ...... ...... ...... ...... ...... /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /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 /bin/install -c -m 644 ./Misc/python.man \ 	/opt/python3/share/man/man1/python3.12.1 if test ! -d /opt/python3/lib/pkgconfig; then \ 	echo "Creating directory /opt/python3/lib/pkgconfig"; \ 	/bin/install -c -d -m 755 /opt/python3/lib/pkgconfig; \ fi if test -f /opt/python3/bin/python3 -o -h /opt/python3/bin/python3; \ then rm -f /opt/python3/bin/python3; \ else true; \ fi (cd /opt/python3/bin; ln -s python3.12 python3) if test "3.12" != "3.12"; then \ 	rm -f /opt/python3/bin/python3.12-config; \ 	(cd /opt/python3/bin; ln -s python3.12-config python3.12-config); \ 	rm -f /opt/python3/lib/pkgconfig/python-3.12.pc; \ 	(cd /opt/python3/lib/pkgconfig; ln -s python-3.12.pc python-3.12.pc); \ 	rm -f /opt/python3/lib/pkgconfig/python-3.12-embed.pc; \ 	(cd /opt/python3/lib/pkgconfig; ln -s python-3.12-embed.pc python-3.12-embed.pc); \ fi rm -f /opt/python3/bin/python3-config (cd /opt/python3/bin; ln -s python3.12-config python3-config) rm -f /opt/python3/lib/pkgconfig/python3.pc (cd /opt/python3/lib/pkgconfig; ln -s python-3.12.pc python3.pc) rm -f /opt/python3/lib/pkgconfig/python3-embed.pc (cd /opt/python3/lib/pkgconfig; ln -s python-3.12-embed.pc python3-embed.pc) rm -f /opt/python3/bin/idle3 (cd /opt/python3/bin; ln -s idle3.12 idle3) rm -f /opt/python3/bin/pydoc3 (cd /opt/python3/bin; ln -s pydoc3.12 pydoc3) rm -f /opt/python3/bin/2to3 (cd /opt/python3/bin; ln -s 2to3-3.12 2to3) if test "x" != "x" ; then \ 	rm -f /opt/python3/bin/python3-32; \ 	(cd /opt/python3/bin; ln -s python3.12-32 python3-32) \ fi if test "x" != "x" ; then \ 	rm -f /opt/python3/bin/python3-intel64; \ 	(cd /opt/python3/bin; ln -s python3.12-intel64 python3-intel64) \ fi rm -f /opt/python3/share/man/man1/python3.1 (cd /opt/python3/share/man/man1; ln -s python3.12.1 python3.1) if test "xupgrade" != "xno"  ; then \ 	case upgrade in \ 		upgrade) ensurepip="--upgrade" ;; \ 		install|*) ensurepip="" ;; \ 	esac; \ 	 ./python -E -m ensurepip \ 		$ensurepip --root=/ ; \ fi Looking in links: /tmp/tmpeykwgd2r Requirement already satisfied: pip in /opt/python3/lib/python3.12/site-packages (24.0) 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 配置环境变量使其生效

[root@localhost ~]# echo "export PYTHON_HOME=/opt/python3"  >> /etc/profile [root@localhost ~]# echo "export PATH=$PYTHON_HOME/bin:$PATH"  >> /etc/profile [root@localhost ~]# source /etc/profile 

2.7 检查是否安装成功

[root@localhost ~]# python3 Python 3.12.4 (main, Jul  4 2024, 09:38:24) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit() [root@localhost ~]# pip3 --version pip 24.0 from /opt/python3/lib/python3.12/site-packages/pip (python 3.12) [root@localhost ~]#  

2.8 编写交互式测试程序测试

[root@localhost ~]# cat python3-test.py  #!/opt/python3 def add(x, y):     return x + y  def subtract(x, y):     return x - y  def multiply(x, y):     return x * y  def divide(x, y):     if y != 0:         return x / y     else:         return "除数不能为0"  while True:     print("选择运算:")     print("1.加法")     print("2.减法")     print("3.乘法")     print("4.除法")     print("5.退出")      choice = input("输入你的选择(1/2/3/4/5): ")      if choice in ('1', '2', '3', '4'):         num1 = float(input("输入第一个数字: "))         num2 = float(input("输入第二个数字: "))          if choice == '1':             print("结果是:", add(num1, num2))          elif choice == '2':             print("结果是:", subtract(num1, num2))          elif choice == '3':             print("结果是:", multiply(num1, num2))          elif choice == '4':             print("结果是:", divide(num1, num2))     elif choice == '5':         print("退出程序。")         break     else:         print("无效输入")  [root@localhost ~]# python3 python3-test.py  选择运算: 1.加法 2.减法 3.乘法 4.除法 5.退出 输入你的选择(1/2/3/4/5): 1 输入第一个数字: 3 输入第二个数字: 65 结果是: 68.0 选择运算: 1.加法 2.减法 3.乘法 4.除法 5.退出 输入你的选择(1/2/3/4/5): 5 退出程序。 

    广告一刻

    为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!