找回密码
 会员注册
查看: 25|回复: 0

CentOS系统上安装Python3.12兼容自带Python2

[复制链接]

2万

主题

0

回帖

6万

积分

超级版主

积分
64419
发表于 2024-9-3 11:49:06 | 显示全部楼层 |阅读模式
目录一、前言二、Python3.12安装1.安装依赖包2.下载并编译Python3.123.补充OpenSSL4.验证python3安装情况5.安装pip对应版本下载并安装 get-pip.py验证pip安装6.其他说明三、卸载Python3一、前言在当今的软件开发和数据科学领域,Python已经成为一种不可或缺的编程语言。然而,许多老旧的系统,如CentOS7.9,默认搭载的是Python2.7,这与Python社区主流的Python3存在显著差异。为了满足现代开发需求,同时保持系统的稳定性和兼容性,我们需要在CentOS7.9上安装并配置Python3.12或更高版本(这里仅以3.12为例),使其与现有的Python2.7共存,并确保能够正常使用pip3管理Python3的包依赖。本文将详细介绍如何在CentOS7.9系统中安装Python3.12,并确保其与系统自带的Python2.7兼容共存。我们将从安装必要的依赖包开始,逐步指导您下载、编译和安装Python3.12,以及配置pip3以管理Python3的包。此外,我们还将探讨如何设置环境变量和别名,以便在命令行中方便地切换和使用不同版本的Python,从而满足大伙在Linux系统中使用Pyhton开发和数据处理方面的多样化需求。二、Python3.12安装1.安装依赖包首先,确保你已经安装了编译Python所需的依赖包:[root@node01opt]#yuminstall-ygccopenssl-develbzip2-devellibffi-develLoadedplugins:fastestmirrorLoadingmirrorspeedsfromcachedhostfileepel/x86_64/metalink|5.1kB00:00:00*base:100.125.0.40*epel:repo.jing.rocks*extras:100.125.0.40*updates:100.125.0.40base|3.6kB00:00:00docker-ce-stable|3.5kB00:00:00extras|2.9kB00:00:00updates|2.9kB00:00:00Packagegcc-4.8.5-44.el7.x86_64alreadyinstalledandlatestversionPackage1penssl-devel-1.0.2k-26.el7_9.x86_64alreadyinstalledandlatestversionPackagelibffi-devel-3.0.13-19.el7.x86_64alreadyinstalledandlatestversionResolvingDependencies-->Runningtransactioncheck--->ackagebzip2-devel.x86_640:1.0.6-13.el7willbeinstalled-->FinishedDependencyResolutionDependenciesResolved=========================================================================================================================================================PackageArchVersionRepositorySize=========================================================================================================================================================Installing:bzip2-develx86_641.0.6-13.el7base218kTransactionSummary=========================================================================================================================================================Install1PackageTotaldownloadsize:218kInstalledsize:382kDownloadingpackages:bzip2-devel-1.0.6-13.el7.x86_64.rpm|218kB00:00:00RunningtransactioncheckRunningtransactiontestTransactiontestsucceededRunningtransactionInstalling:bzip2-devel-1.0.6-13.el7.x86_641/1Verifying:bzip2-devel-1.0.6-13.el7.x86_641/1Installed:bzip2-devel.x86_640:1.0.6-13.el7Complete!2.下载并编译Python3.12这里推荐到华为云python下载目录自行查看,因为python官网基本下不动 。这里我们先下载Python3.12 的源代码。[root@node01opt]#wgethttps://mirrors.huaweicloud.com/python/3.12.0/Python-3.12.0.tgz--2024-08-0919:56:12--https://mirrors.huaweicloud.com/python/3.12.0/Python-3.12.0.tgzResolvingmirrors.huaweicloud.com(mirrors.huaweicloud.com)...124.70.125.153,124.70.125.167Connectingtomirrors.huaweicloud.com(mirrors.huaweicloud.com)|124.70.125.153|:443...connected.HTTPrequestsent,awaitingresponse...200Length:27195214(26M)[application/octet-stream]Savingto:‘Python-3.12.0.tgz’100%[===============================================================================================================>]27,195,21449.3MB/sin0.5s2024-08-0919:56:13(49.3MB/s)-‘Python-3.12.0.tgz’saved[27195214/27195214]然后解压进行编译安装: [root@node01opt]#tarxfPython-3.12.0.tgz[root@node01opt]#cdPython-3.12.0[root@node01Python-3.12.0]#lltotal1460-rw-------1adminadmin24436Oct22023aclocal.m4-rwx------1adminadmin49348Oct22023config.guess-rwx------1adminadmin35276Oct22023config.sub-rwx------1adminadmin869735Oct22023configure-rw-------1adminadmin234218Oct22023configure.acdrwx------17adminadmin4096Oct22023Docdrwx------2adminadmin4096Oct22023Grammardrwx------4adminadmin4096Oct22023Include-rwx------1adminadmin15358Oct22023install-shdrwx------37adminadmin4096Oct22023Lib-rw-------1adminadmin13936Oct22023LICENSEdrwx------8adminadmin4096Oct22023Mac-rw-------1adminadmin107531Oct22023Makefile.pre.indrwx------3adminadmin4096Oct22023Miscdrwx------16adminadmin4096Oct22023Modulesdrwx------4adminadmin4096Oct22023Objectsdrwx------2adminadmin4096Oct22023Parserdrwx------5adminadmin4096Oct22023PCdrwx------2adminadmin4096Oct22023PCbuilddrwx------2adminadmin4096Oct22023Programs-rw-------1adminadmin53286Oct22023pyconfig.h.indrwx------5adminadmin4096Oct22023Python-rw-------1adminadmin9083Oct22023README.rstdrwx------24adminadmin4096Oct22023Tools然后进行安装:#这里也可以使用--prefix=targetpath指定安装目录[root@node01Python-3.12.0]#./configure--enable-optimizationscheckingbuildsystemtype...x86_64-pc-linux-gnucheckinghostsystemtype...x86_64-pc-linux-gnucheckingforPythoninterpreterfreezing..../_bootstrap_pythoncheckingforpython3.12...nocheckingforpython3.12...nocheckingforpython3.11...nocheckingforpython3.10...nocheckingforpython3...nocheckingforpython...pythoncheckingPythonforregenversion...checkingforpkg-config.../usr/bin/pkg-configcheckingpkg-configisatleastversion0.9.0...yescheckingfor--enable-universalsdk...nocheckingfor--with-universal-archs...nocheckingMACHDEP..."linux"checkingforgcc...gcccheckingwhethertheCcompilerworks...yescheckingforCcompilerdefaultoutputfilename...a.outcheckingforsuffixofexecutables...checkingwhetherwearecrosscompiling...nocheckingforsuffixofobjectfiles...ocheckingwhetherthecompilersupportsGNUC...yescheckingwhethergccaccepts-g...yescheckingforgccoptiontoenableC11features...-std=gnu11checkinghowtoruntheCpreprocessor...gcc-std=gnu11-Echeckingforgrepthathandleslonglinesand-e.../usr/bin/grepcheckingforasedthatdoesnottruncateoutput.../usr/bin/sedcheckingforegrep.../usr/bin/grep-EcheckingforCCcompilername...gcccheckingforstdio.h...yescheckingforstdlib.h...yescheckingforstring.h...yescheckingforinttypes.h...yescheckingforstdint.h...yescheckingforstrings.h...yescheckingforsys/stat.h...yescheckingforsys/types.h...yescheckingforunistd.h...yescheckingforwchar.h...yescheckingforminix/config.h...nocheckingwhetheritissafetodefine__EXTENSIONS__...yescheckingwhether_XOPEN_SOURCEshouldbedefined...nocheckingforc++...c++configure:Bydefault,distutilswillbuildC++extensionmoduleswith"c++".Ifthisisnotintended,thensetCXXontheconfigurecommandline.checkingfortheplatformtripletbasedoncompilercharacteristics...x86_64-linux-gnucheckingformultiarch...checkingforPEP11supporttier...x86_64-pc-linux-gnu/gcchastier1(supported)checkingfor-Wl,--no-as-needed...yescheckingfortheAndroidAPIlevel...notAndroidcheckingfor--with-emscripten-target...checkingfor--enable-wasm-dynamic-linking...missingcheckingfor--enable-wasm-pthreads...missingcheckingfor--with-suffix...checkingforcase-insensitivebuilddirectory...nocheckingLIBRARY...libpython$(VERSION)$(ABIFLAGS).acheckingLINKCC...$(PURIFY)$(CC)checkingEXPORTSYMS...checkingforGNUld...yescheckingfor--enable-shared...nocheckingfor--with-static-libpython...yescheckingfor--enable-profiling...nocheckingLDLIBRARY...checkingHOSTRUNNER...libpython$(VERSION)$(ABIFLAGS).acheckingforar...archeckingforaBSD-compatibleinstall.../usr/bin/install-ccheckingforarace-freemkdir-p.../usr/bin/mkdir-pcheckingfor--with-pydebug...nocheckingfor--with-trace-refs...nocheckingfor--enable-pystats...nocheckingfor--with-assertions...nocheckingfor--enable-optimizations...yescheckingwhetherCcompileraccepts-fno-semantic-interposition...nocheckingPROFILE_TASK...-mtest--pgo--timeout=$(TESTTIMEOUT)checkingfor--with-lto...nocheckingforllvm-profdata...nocheckingfor--enable-bolt...nocheckingBOLT_INSTRUMENT_FLAGS...checkingBOLT_APPLY_FLAGS...-update-debug-sections-reorder-blocks=ext-tsp-reorder-functions=hfsort+-split-functions-icf=1-inline-all-split-eh-reorder-functions-use-hot-size-peepholes=none-jump-tables=aggressive-inline-ap-indirect-call-promotion=all-dyno-stats-use-gnu-stack-frame-opt=hotcheckingifgcc-std=gnu11supports-fstrict-overflowand-fno-strict-overflow...yescheckingfor--with-strict-overflow...nocheckingifgcc-std=gnu11supports-Ogoptimizationlevel...yescheckingifwecanadd-Wextra...yescheckingwhethergcc-std=gnu11-fno-strict-aliasingacceptsandneeds-fno-strict-aliasing...nocheckingifwecandisablegcc-std=gnu11unused-parameterwarning...yescheckingifwecandisablegcc-std=gnu11int-conversionwarning...nocheckingifwecandisablegcc-std=gnu11missing-field-initializerswarning...yescheckingifwecanenablegcc-std=gnu11sign-comparewarning...yescheckingifwecanenablegcc-std=gnu11unreachable-codewarning...yescheckingifwecanenablegcc-std=gnu11strict-prototypeswarning...yescheckingifwecanmakeimplicitfunctiondeclarationanerroringcc-std=gnu11-Werror=implicit-function-declaration...yescheckingifwecanusevisibilityingcc-std=gnu11-fvisibility=hidden...yescheckingwhetherpthreadsareavailablewithoutoptions...nocheckingwhethergcc-std=gnu11accepts-Kpthread...nocheckingwhethergcc-std=gnu11accepts-Kthread...nocheckingwhethergcc-std=gnu11accepts-pthread...yescheckingwhetherc++alsoacceptsflagsforthreadsupport...yescheckingforalloca.h...yescheckingforasm/types.h...yescheckingforbluetooth.h...nocheckingforconio.h...nocheckingforcrypt.h...yescheckingfordirect.h...nocheckingfordlfcn.h...yescheckingforendian.h...yescheckingforerrno.h...yescheckingforfcntl.h...yescheckingforgrp.h...yescheckingforieeefp.h...nocheckingforio.h...nocheckingforlanginfo.h...yescheckingforlibintl.h...yescheckingforlibutil.h...nocheckingforlinux/auxvec.h...yescheckingforsys/auxv.h...yescheckingforlinux/fs.h...yescheckingforlinux/limits.h...yescheckingforlinux/memfd.h...yescheckingforlinux/random.h...yescheckingforlinux/soundcard.h...yescheckingforlinux/tipc.h...yescheckingforlinux/wait.h...yescheckingfornetdb.h...yescheckingfornet/ethernet.h...yescheckingfornetinet/in.h...yescheckingfornetpacket/packet.h...yescheckingforpoll.h...yescheckingforprocess.h...nocheckingforpthread.h...yescheckingforpty.h...yescheckingforsched.h...yescheckingforsetjmp.h...yescheckingforshadow.h...yescheckingforsignal.h...yescheckingforspawn.h...yescheckingforstropts.h...nocheckingforsys/audioio.h...nocheckingforsys/bsdtty.h...nocheckingforsys/devpoll.h...nocheckingforsys/endian.h...nocheckingforsys/epoll.h...yescheckingforsys/event.h...nocheckingforsys/eventfd.h...yescheckingforsys/file.h...yescheckingforsys/ioctl.h...yescheckingforsys/kern_control.h...nocheckingforsys/loadavg.h...nocheckingforsys/lock.h...nocheckingforsys/memfd.h...nocheckingforsys/mkdev.h...nocheckingforsys/mman.h...yescheckingforsys/modem.h...nocheckingforsys/param.h...yescheckingforsys/poll.h...yescheckingforsys/random.h...nocheckingforsys/resource.h...yescheckingforsys/select.h...yescheckingforsys/sendfile.h...yescheckingforsys/socket.h...yescheckingforsys/soundcard.h...yescheckingforsys/stat.h...(cached)yescheckingforsys/statvfs.h...yescheckingforsys/sys_domain.h...nocheckingforsys/syscall.h...yescheckingforsys/sysmacros.h...yescheckingforsys/termio.h...nocheckingforsys/time.h...yescheckingforsys/times.h...yescheckingforsys/types.h...(cached)yescheckingforsys/uio.h...yescheckingforsys/un.h...yescheckingforsys/utsname.h...yescheckingforsys/wait.h...yescheckingforsys/xattr.h...yescheckingforsysexits.h...yescheckingforsyslog.h...yescheckingfortermios.h...yescheckingforutil.h...nocheckingforutime.h...yescheckingforutmp.h...yescheckingfordirent.hthatdefinesDIR...yescheckingforlibrarycontainingopendir...nonerequiredcheckingforsys/mkdev.h...(cached)nocheckingforsys/sysmacros.h...(cached)yescheckingforbluetooth/bluetooth.h...nocheckingfornet/if.h...yescheckingforlinux/netlink.h...yescheckingforlinux/qrtr.h...nocheckingforlinux/vm_sockets.h...yescheckingforlinux/can.h...yescheckingforlinux/can/bcm.h...yescheckingforlinux/can/j1939.h...nocheckingforlinux/can/raw.h...yescheckingfornetcan/can.h...nocheckingforclock_tintime.h...yescheckingformakedev...yescheckingforle64toh...yescheckingformode_t...yescheckingforoff_t...yescheckingforpid_t...yescheckingforsize_t...yescheckingforuid_tinsys/types.h...yescheckingforssize_t...yescheckingfor__uint128_t...yescheckingsizeofint...4checkingsizeoflong...8checkingalignmentoflong...8checkingsizeoflonglong...8checkingsizeofvoid*...8checkingsizeofshort...2checkingsizeoffloat...4checkingsizeofdouble...8checkingsizeoffpos_t...16checkingsizeofsize_t...8checkingalignmentofsize_t...8checkingsizeofpid_t...4checkingsizeofuintptr_t...8checkingalignmentofmax_align_t...16checkingforlongdouble...yescheckingsizeoflongdouble...16checkingsizeof_Bool...1checkingsizeofoff_t...8checkingwhethertoenablelargefilesupport...nocheckingsizeoftime_t...8checkingforpthread_t...yescheckingsizeofpthread_t...8checkingsizeofpthread_key_t...4checkingwhetherpthread_key_tiscompatiblewithint...yescheckingfor--enable-framework...nocheckingfor--with-dsymutil...nocheckingfordyld...nocheckingfor--with-address-sanitizer...nocheckingfor--with-memory-sanitizer...nocheckingfor--with-undefined-behavior-sanitizer...nocheckingtheextensionofsharedlibraries....socheckingLDSHARED...$(CC)-sharedcheckingBLDSHAREDflags...$(CC)-sharedcheckingCCSHARED...-fPICcheckingLINKFORSHARED...-Xlinker-export-dynamiccheckingCFLAGSFORSHARED...checkingSHLIBS...$(LIBS)checkingperftrampoline...yescheckingforsendfilein-lsendfile...nocheckingfordlopenin-ldl...yescheckingforshl_loadin-ldld...nocheckingforuuid.h...nocheckingforLIBUUID...nocheckingforuuid/uuid.h...nocheckingforuuid/uuid.h...(cached)nocheckingforlibrarycontainingsem_init...-lpthreadcheckingfortextdomainin-lintl...nocheckingalignedmemoryaccessisrequired...nocheckingfor--with-hash-algorithm...defaultcheckingfor--with-tzpath..."/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo"checkingfort_openin-lnsl...nocheckingforsocketin-lsocket...nocheckingfor--with-libs...nocheckingfor--with-system-expat...nocheckingforLIBFFI...yescheckingforffi_prep_cif_var...yescheckingforffi_prep_closure_loc...yescheckingforffi_closure_alloc...yescheckingfor--with-system-libmpdec...nocheckingfor--with-decimal-contextvar...yescheckingfordecimallibmpdecmachine...uint128checkingforLIBNSL...nocheckingforlibrarycontainingyp_match...-lnslcheckingforrpc/rpc.h...yescheckingforLIBSQLITE3...nocheckingforsqlite3.h...nocheckingfor--enable-loadable-sqlite-extensions...nocheckingforgdbm.h...nocheckingforndbm.h...nocheckingforndbmpresenceandlinkerargs...()checkingforgdbm/ndbm.h...nocheckingforgdbm-ndbm.h...nocheckingfordb.h...nocheckingfor--with-dbmliborder...gdbm:ndbm:bdbcheckingfor_dbmmoduleCFLAGSandLIBS...checkingifPTHREAD_SCOPE_SYSTEMissupported...yescheckingforpthread_sigmask...yescheckingforpthread_getcpuclockid...yescheckingif--enable-ipv6isspecified...yescheckingifRFC2553APIisavailable...yescheckingipv6stacktype...linux-glibccheckingCAN_RAW_FD_FRAMES...yescheckingforCAN_RAW_JOIN_FILTERS...yescheckingfor--with-doc-strings...yescheckingfor--with-pymalloc...yescheckingfor--with-freelists...yescheckingfor--with-c-locale-coercion...yescheckingfor--with-valgrind...nocheckingfor--with-dtrace...nocheckingfordlopen...yescheckingDYNLOADFILE...dynload_shlib.ocheckingMACHDEP_OBJS...nonecheckingforaccept4...yescheckingforalarm...yescheckingforbind_textdomain_codeset...yescheckingforchmod...yescheckingforchown...yescheckingforclock...yescheckingforclose_range...nocheckingforconfstr...yescheckingforcopy_file_range...nocheckingforctermid...yescheckingfordup...yescheckingfordup3...yescheckingforexecv...yescheckingforexplicit_bzero...nocheckingforexplicit_memset...nocheckingforfaccessat...yescheckingforfchmod...yescheckingforfchmodat...yescheckingforfchown...yescheckingforfchownat...yescheckingforfdopendir...yescheckingforfdwalk...nocheckingforfexecve...yescheckingforfork...yescheckingforfork1...nocheckingforfpathconf...yescheckingforfstatat...yescheckingforftime...yescheckingforftruncate...yescheckingforfutimens...yescheckingforfutimes...yescheckingforfutimesat...yescheckingforgai_strerror...yescheckingforgetegid...yescheckingforgetentropy...nocheckingforgeteuid...yescheckingforgetgid...yescheckingforgetgrgid...yescheckingforgetgrgid_r...yescheckingforgetgrnam_r...yescheckingforgetgrouplist...yescheckingforgetgroups...yescheckingforgethostname...yescheckingforgetitimer...yescheckingforgetloadavg...yescheckingforgetlogin...yescheckingforgetpeername...yescheckingforgetpgid...yescheckingforgetpid...yescheckingforgetppid...yescheckingforgetpriority...yescheckingfor_getpty...nocheckingforgetpwent...yescheckingforgetpwnam_r...yescheckingforgetpwuid...yescheckingforgetpwuid_r...yescheckingforgetresgid...yescheckingforgetresuid...yescheckingforgetrusage...yescheckingforgetsid...yescheckingforgetspent...yescheckingforgetspnam...yescheckingforgetuid...yescheckingforgetwd...yescheckingforif_nameindex...yescheckingforinitgroups...yescheckingforkill...yescheckingforkillpg...yescheckingforlchown...yescheckingforlinkat...yescheckingforlockf...yescheckingforlstat...yescheckingforlutimes...yescheckingformadvise...yescheckingformbrtowc...yescheckingformemrchr...yescheckingformkdirat...yescheckingformkfifo...yescheckingformkfifoat...yescheckingformknod...yescheckingformknodat...yescheckingformktime...yescheckingformmap...yescheckingformremap...yescheckingfornice...yescheckingforopenat...yescheckingforopendir...yescheckingforpathconf...yescheckingforpause...yescheckingforpipe...yescheckingforpipe2...yescheckingforplock...nocheckingforpoll...yescheckingforposix_fadvise...yescheckingforposix_fallocate...yescheckingforposix_spawn...yescheckingforposix_spawnp...yescheckingforpread...yescheckingforpreadv...yescheckingforpreadv2...nocheckingforpthread_condattr_setclock...yescheckingforpthread_init...nocheckingforpthread_kill...yescheckingforpwrite...yescheckingforpwritev...yescheckingforpwritev2...nocheckingforreadlink...yescheckingforreadlinkat...yescheckingforreadv...yescheckingforrealpath...yescheckingforrenameat...yescheckingforrtpSpawn...nocheckingforsched_get_priority_max...yescheckingforsched_rr_get_interval...yescheckingforsched_setaffinity...yescheckingforsched_setparam...yescheckingforsched_setscheduler...yescheckingforsem_clockwait...nocheckingforsem_getvalue...yescheckingforsem_open...yescheckingforsem_timedwait...yescheckingforsem_unlink...yescheckingforsendfile...yescheckingforsetegid...yescheckingforseteuid...yescheckingforsetgid...yescheckingforsethostname...yescheckingforsetitimer...yescheckingforsetlocale...yescheckingforsetpgid...yescheckingforsetpgrp...yescheckingforsetpriority...yescheckingforsetregid...yescheckingforsetresgid...yescheckingforsetresuid...yescheckingforsetreuid...yescheckingforsetsid...yescheckingforsetuid...yescheckingforsetvbuf...yescheckingforshutdown...yescheckingforsigaction...yescheckingforsigaltstack...yescheckingforsigfillset...yescheckingforsiginterrupt...yescheckingforsigpending...yescheckingforsigrelse...yescheckingforsigtimedwait...yescheckingforsigwait...yescheckingforsigwaitinfo...yescheckingforsnprintf...yescheckingforsplice...yescheckingforstrftime...yescheckingforstrlcpy...nocheckingforstrsignal...yescheckingforsymlinkat...yescheckingforsync...yescheckingforsysconf...yescheckingforsystem...yescheckingfortcgetpgrp...yescheckingfortcsetpgrp...yescheckingfortempnam...yescheckingfortimegm...yescheckingfortimes...yescheckingfortmpfile...yescheckingfortmpnam...yescheckingfortmpnam_r...yescheckingfortruncate...yescheckingforttyname...yescheckingforumask...yescheckingforuname...yescheckingforunlinkat...yescheckingforutimensat...yescheckingforutimes...yescheckingforvfork...yescheckingforwait...yescheckingforwait3...yescheckingforwait4...yescheckingforwaitid...yescheckingforwaitpid...yescheckingforwcscoll...yescheckingforwcsftime...yescheckingforwcsxfrm...yescheckingforwmemcmp...yescheckingforwritev...yescheckingforgcc-std=gnu11-pthreadoptionsneededtodetectallundeclaredfunctions...noneneededcheckingwhetherdirfdisdeclared...yescheckingforchroot...yescheckingforlink...yescheckingforsymlink...yescheckingforfchdir...yescheckingforfsync...yescheckingforfdatasync...yescheckingforepoll_create...yescheckingforepoll_create1...yescheckingforkqueue...nocheckingforprlimit...yescheckingfor_dyld_shared_cache_contains_path...nocheckingformemfd_create...nocheckingforeventfd...yescheckingforctermid_r...nocheckingforflockdeclaration...yescheckingforflock...yescheckingforgetpagesize...yescheckingforbrokenunsetenv...nocheckingfortrue...truecheckingforinet_atonin-lc...yescheckingforchflags...nocheckingforlchflags...nocheckingforZLIB...yescheckingforBZIP2...nocheckingforbzlib.h...yescheckingforBZ2_bzCompressin-lbz2...yescheckingforLIBLZMA...nocheckingforlzma.h...nocheckingforhstrerror...yescheckingforgetservbyname...yescheckingforgetservbyport...yescheckingforgethostbyname...yescheckingforgethostbyaddr...yescheckingforgetprotobyname...yescheckingforinet_aton...yescheckingforinet_ntoa...yescheckingforinet_pton...yescheckingforgetpeername...(cached)yescheckingforgetsockname...yescheckingforaccept...yescheckingforbind...yescheckingforconnect...yescheckingforlisten...yescheckingforrecvfrom...yescheckingforsendto...yescheckingforsetsockopt...yescheckingforsocket...yescheckingforsetgroups...yescheckingforopenpty...nocheckingforopenptyin-lutil...yescheckingforlibrarycontaininglogin_tty...nonerequiredcheckingforforkpty...yescheckingforfseek64...nocheckingforfseeko...yescheckingforfstatvfs...yescheckingforftell64...nocheckingforftello...yescheckingforstatvfs...yescheckingfordup2...yescheckingforgetpgrp...yescheckingforsetpgrp...(cached)yescheckingforsetns...yescheckingforunshare...yescheckingforLIBCRYPT...nocheckingforlibrarycontainingcrypt_r...-lcryptcheckingforcryptorcrypt_r...yescheckingforclock_gettime...yescheckingforclock_getres...yescheckingforclock_settime...yescheckingforclock_nanosleep...yescheckingfornanosleep...yescheckingformajor,minor,andmakedev...yescheckingforgetaddrinfo...yescheckinggetaddrinfobug...nocheckingforgetnameinfo...yescheckingwhetherstructtmisinsys/time.hortime.h...time.hcheckingforstructtm.tm_zone...yescheckingforstructstat.st_rdev...yescheckingforstructstat.st_blksize...yescheckingforstructstat.st_flags...nocheckingforstructstat.st_gen...nocheckingforstructstat.st_birthtime...nocheckingforstructstat.st_blocks...yescheckingforstructpasswd.pw_gecos...yescheckingforstructpasswd.pw_passwd...yescheckingforsiginfo_t.si_band...yescheckingfortime.hthatdefinesaltzone...nocheckingforaddrinfo...yescheckingforsockaddr_storage...yescheckingforsockaddr_alg...yescheckingforanANSIC-conformingconst...yescheckingforworkingsignedchar...yescheckingforprototypes...yescheckingforsocketpair...yescheckingifsockaddrhassa_lenmember...nocheckingforgethostbyname_r...yescheckinggethostbyname_rwith6args...yescheckingfor__fpu_control...yescheckingfor--with-libm=STRING...defaultLIBM="-lm"checkingfor--with-libc=STRING...defaultLIBC=""checkingforx64gccinlineassembler...yescheckingwhetherfloatwordorderingisbigendian...nocheckingwhetherwecanusegccinlineassemblertogetandsetx87controlword...yescheckingwhetherwecanusegccinlineassemblertogetandsetmc68881fpcr...nocheckingforx87-styledoublerounding...nocheckingforacosh...yescheckingforasinh...yescheckingforatanh...yescheckingforerf...yescheckingforerfc...yescheckingforexpm1...yescheckingforlog1p...yescheckingforlog2...yescheckingwhetherPOSIXsemaphoresareenabled...yescheckingforbrokensem_getvalue...nocheckingwhetherRTLD_LAZYisdeclared...yescheckingwhetherRTLD_NOWisdeclared...yescheckingwhetherRTLD_GLOBALisdeclared...yescheckingwhetherRTLD_LOCALisdeclared...yescheckingwhetherRTLD_NODELETEisdeclared...yescheckingwhetherRTLD_NOLOADisdeclared...yescheckingwhetherRTLD_DEEPBINDisdeclared...yescheckingwhetherRTLD_MEMBERisdeclared...nocheckingdigitsizeforPython'slongs...novaluespecifiedcheckingforwchar.h...(cached)yescheckingsizeofwchar_t...4checkingwhetherwchar_tissigned...yescheckingwhetherwchar_tisusable...nocheckingwhetherbyteorderingisbigendian...nocheckingABIFLAGS...checkingSOABI...cpython-312-x86_64-linux-gnucheckingLDVERSION...$(VERSION)$(ABIFLAGS)checkingfor--with-platlibdir...nocheckingfor--with-wheel-pkg-dir...nocheckingwhetherrightshiftextendsthesignbit...yescheckingforgetc_unlocked()andfriends...yescheckingforLIBREADLINE...nocheckingforreadline/readline.h...nocheckinghowtolinkreadline...nocheckingforbrokennice()...nocheckingforbrokenpoll()...nocheckingforworkingtzset()...yescheckingfortv_nsecinstructstat...yescheckingfortv_nsec2instructstat...nocheckingforcurses.h...nocheckingforncurses.h...nocheckingcursesmoduleflags...nocheckingforpanel.h...nocheckingpanelflags...nocheckingforterm.h...nocheckingwhethermvwdelchisanexpression...nocheckingwhetherWINDOWhas_flags...nocheckingforcursesfunctionis_pad...nocheckingforcursesfunctionis_term_resized...nocheckingforcursesfunctionresize_term...nocheckingforcursesfunctionresizeterm...nocheckingforcursesfunctionimmedok...nocheckingforcursesfunctionsyncok...nocheckingforcursesfunctionwchgat...nocheckingforcursesfunctionfilter...nocheckingforcursesfunctionhas_key...nocheckingforcursesfunctiontypeahead...nocheckingforcursesfunctionuse_env...noconfigure:checkingfordevicefilescheckingfor/dev/ptmx...yescheckingfor/dev/ptc...nocheckingforsocklen_t...yescheckingforbrokenmbstowcs...nocheckingfor--with-computed-gotos...novaluespecifiedcheckingwhethergcc-std=gnu11-pthreadsupportscomputedgotos...yescheckingforbuilddirectories...donecheckingfor-O2...yescheckingforglibc_FORTIFY_SOURCE/memmovebug...nocheckingforgccipa-pure-constbug...nocheckingforstdatomic.h...nocheckingforbuiltin__atomic_load_nand__atomic_store_nfunctions...yescheckingforensurepip...upgradecheckingifthedirentstructureofad_typefield...yescheckingfortheLinuxgetrandom()syscall...yescheckingforthegetrandom()function...nocheckingforlibrarycontainingshm_open...-lrtcheckingforshm_open...yescheckingforshm_unlink...yescheckingforpkg-config.../usr/bin/pkg-configcheckingwhethercompilingandlinkingagainstOpenSSLworks...yescheckingfor--with-openssl-rpath...checkingwhetherOpenSSLprovidesrequiredsslmoduleAPIs...nocheckingwhetherOpenSSLprovidesrequiredhashlibmoduleAPIs...nocheckingfor--with-ssl-default-suites...pythoncheckingfor--with-builtin-hashlib-hashes...md5,sha1,sha2,sha3,blake2checkingforLIBB2...nocheckingfor--disable-test-modules...yescheckingforstdlibextensionmodule_multiprocessing...yescheckingforstdlibextensionmodule_posixshmem...yescheckingforstdlibextensionmodulefcntl...yescheckingforstdlibextensionmodulemmap...yescheckingforstdlibextensionmodule_socket...yescheckingforstdlibextensionmodulegrp...yescheckingforstdlibextensionmoduleossaudiodev...yescheckingforstdlibextensionmodulepwd...yescheckingforstdlibextensionmoduleresource...yescheckingforstdlibextensionmodule_scproxy...n/acheckingforstdlibextensionmodulespwd...yescheckingforstdlibextensionmodulesyslog...yescheckingforstdlibextensionmoduletermios...yescheckingforstdlibextensionmodulepyexpat...yescheckingforstdlibextensionmodule_elementtree...yescheckingforstdlibextensionmodule_md5...yescheckingforstdlibextensionmodule_sha1...yescheckingforstdlibextensionmodule_sha2...yescheckingforstdlibextensionmodule_sha3...yescheckingforstdlibextensionmodule_blake2...yescheckingforstdlibextensionmodule_crypt...yescheckingforstdlibextensionmodule_ctypes...yescheckingforstdlibextensionmodule_curses...missingcheckingforstdlibextensionmodule_curses_panel...missingcheckingforstdlibextensionmodule_decimal...yescheckingforstdlibextensionmodule_dbm...missingcheckingforstdlibextensionmodule_gdbm...missingcheckingforstdlibextensionmodulenis...yescheckingforstdlibextensionmodulereadline...missingcheckingforstdlibextensionmodule_sqlite3...disabledcheckingforstdlibextensionmodule_tkinter...missingcheckingforstdlibextensionmodule_uuid...missingcheckingforstdlibextensionmodulezlib...yescheckingforstdlibextensionmodule_bz2...yescheckingforstdlibextensionmodule_lzma...missingcheckingforstdlibextensionmodule_ssl...missingcheckingforstdlibextensionmodule_hashlib...missingcheckingforstdlibextensionmodule_testcapi...yescheckingforstdlibextensionmodule_testclinic...yescheckingforstdlibextensionmodule_testinternalcapi...yescheckingforstdlibextensionmodule_testbuffer...yescheckingforstdlibextensionmodule_testimportmultiple...yescheckingforstdlibextensionmodule_testmultiphase...yescheckingforstdlibextensionmodulexxsubtype...yescheckingforstdlibextensionmodule_xxtestfuzz...yescheckingforstdlibextensionmodule_ctypes_test...yescheckingforstdlibextensionmodulexxlimited...yescheckingforstdlibextensionmodulexxlimited_35...yesconfigure:creating./config.statusconfig.status:creatingMakefile.preconfig.status:creatingMisc/python.pcconfig.status:creatingMisc/python-embed.pcconfig.status:creatingMisc/python-config.shconfig.status:creatingModules/Setup.bootstrapconfig.status:creatingModules/Setup.stdlibconfig.status:creatingModules/ld_so_aixconfig.status:creatingpyconfig.hconfigure:creatingModules/Setup.localconfigure:creatingMakefile注意:使用 altinstall 而不是 install,以避免覆盖系统默认的Python版本。但是装着装着就会出现一个这样的东西出来:这是由于python3.10之后版本不在支持libressl使用ssl,需要使用openssl安装来解决编译安装python时候遇到的ssl模块导入失败的问题,这里需要用的openssl1.1.1版本或者更高版本。3.补充OpenSSL这里以openssl-1.1.1为例,官网下载速度太慢,这里我直接下载以前用过的离线包了。有需要的小伙伴可以在笔者资源里自取。[root@node01opt]#tarzxfopenssl-1.1.1t.tar.gz[root@node01opt]#cdopenssl-1.1.1t#指定安装的地址[root@node01openssl-1.1.1t]#./config--prefix=/usr/local/opensslOperatingsystem:x86_64-whatever-linux2ConfiguringOpenSSLversion1.1.1t(0x1010114fL)forlinux-x86_64Usingos-specificseedconfigurationCreatingconfigdata.pmCreatingMakefile*******************************************************************************OpenSSLhasbeensuccessfullyconfigured************Ifyouencounteraproblemwhilebuilding,pleaseopenan******issueonGitHub******andincludetheoutputfromthefollowingcommand:************perlconfigdata.pm--dump************(IfyouarenewtoOpenSSL,youmightwanttoconsultthe******'Troubleshooting'sectionintheINSTALLfilefirst)*******************************************************************************[root@node01openssl-1.1.1t]#make-j&makeinstall…… 然后等待它一段时间安装完成后,我们需要重新进入python3.12的安装目录,清理一下之前编译过的python信息,然后重新编译:[root@node01openssl-1.1.1t]#cd/opt/Python-3.12.0[root@node01Python-3.12.0]#makecleanfind.-depth-name'__pycache__'-execrm-rf{}';'find.-name'*.py[co]'-execrm-f{}';'find.-name'*.[oa]'-execrm-f{}';'find.-name'*.s[ol]'-execrm-f{}';'find.-name'*.so.[0-9]*.[0-9]*'-execrm-f{}';'find.-name'*.lto'-execrm-f{}';'find.-name'*.wasm'-execrm-f{}';'find.-name'*.lst'-execrm-f{}';'findbuild-name'fficonfig.h'-execrm-f{}';'||truefindbuild-name'*.py'-execrm-f{}';'||truefindbuild-name'*.py[co]'-execrm-f{}';'||truerm-fpybuilddir.txtrm-fLib/lib2to3/*Grammar*.picklerm-f_bootstrap_pythonrm-fpython.htmlpython*.jspython.datapython*.symbolspython*.maprm-f./usr/local/lib/python3.12/os.pyrm-fPrograms/_testembedPrograms/_freeze_modulerm-fPython/deepfreeze/*.[co]rm-fPython/frozen_modules/*.hrm-fPython/frozen_modules/MANIFESTfindbuild-typef-a!-name'*.gc??'-execrm-f{}';'rm-fInclude/pydtrace_probes.hrm-fprofile-gen-stamp#Profiledata.rm-f*.fdata#PristinebinariesbeforeBOLToptimization.rm-f*.prebolt#BOLTinstrumentedbinaries.rm-f*.bolt_instmake[1]:Enteringdirectory`/opt/Python-3.12.0'find.-name'*.gc??'-execrm-f{}';'find.-name'*.profclang?'-execrm-f{}';'find.-name'*.dyn'-execrm-f{}';'rm-f/opt/Python-3.12.0/coverage.inform-rf/opt/Python-3.12.0/lcov-reportrm-fprofile-run-stamprm-fprofile-bolt-stampmake[1]eavingdirectory`/opt/Python-3.12.0'#带上openssl重新开始[root@node01Python-3.12.0]#./configure--with-openssl=/usr/local/openssl--with-openssl-rpath=auto这次带上openssl重新安装就可以了。最后重新make一下即可。[root@node01Python-3.12.0]#make-j&makeinstall……4.验证python3安装情况验证Python3.10是否安装成功:[root@node01admin]#/usr/local/bin/python3.12--versionPython3.12.0但是这样验证版本比较麻烦,时间长了如果不记得是否安装位置,或者使用的时候很不方便,因此可以在设置一下Python3的默认版本。 4.设置默认Python版本安装完成后,我们可以通过建立软链接的方式来设置默认的Python版本:[root@node01admin]#ln-sf/usr/local/bin/python3.12/usr/bin/python3[root@node01admin]#python3--versionPython3.12.0[root@node01admin]#python2--versionPython2.7.5这样在使用不同版本的python时就方便多了。 然后我们可以看一下opensslen模块是不是正常的:[root@node01admin]#python3-c"importssl;print(ssl.OPENSSL_VERSION)"OpenSSL1.1.1t7Feb2023 正常显示咱们的安装版本即可。5.安装pip对应版本同样的,作为python的包管理工具pip也很重要,一般情况下像python3.12在安装的时候会自动安装对应的pip。如果有时候没有安装也不要紧,只需要获取其脚本后用python安装即可。安装 pip 对应版本的方法如下:下载并安装 get-pip.py[root@node01admin]#wgethttps://bootstrap.pypa.io/get-pip.py[root@node01admin]#/usr/local/bin/python3.12get-pip.py验证pip安装同样也可以以建立软链接的方式设置一下默认方式并查验:[root@node01admin]#whereispippip:/usr/local/bin/pip3.12[root@node01admin]#/usr/local/bin/pip3.12--versionpip23.2.1from/usr/local/lib/python3.12/site-packages/pip(python3.12)[root@node01admin]#ln-sf/usr/local/bin/pip3.12/usr/bin/pip3[root@node01admin]#pip3--versionpip23.2.1from/usr/local/lib/python3.12/site-packages/pip(python3.12)6.其他说明需要注意的是,一般情况pip3默认使用的网络连接源都比较差,比如直接下载pandas的时候可能会出现这种问题:[root@node01admin]#pip3installpandasWARNING:Retrying(Retry(total=4,connect=None,read=None,redirect=None,status=None))afterconnectionbrokenby'NewConnectionError(' :Failedtoestablishanewconnection:[Errno101]Networkisunreachable')':/simple/pandas/CollectingpandasObtainingdependencyinformationforpandasfromhttps://files.pythonhosted.org/packages/40/10/79e52ef01dfeb1c1ca47a109a01a248754ebe990e159a844ece12914de83/pandas-2.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata所以一般建议在使用的时候最好指定国内镜像源来进行下载:[root@node01admin]#pip3install-ihttps://pypi.tuna.tsinghua.edu.cn/simplepandasLookinginindexes:https://pypi.tuna.tsinghua.edu.cn/simpleCollectingpandasDownloadinghttps://pypi.tuna.tsinghua.edu.cn/packages/40/10/79e52ef01dfeb1c1ca47a109a01a248754ebe990e159a844ece12914de83/pandas-2.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl(12.7MB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━12.7/12.7MB55.9MB/seta0:00:00Collectingnumpy>=1.26.0(frompandas)Downloadinghttps://pypi.tuna.tsinghua.edu.cn/packages/2c/f3/61eeef119beb37decb58e7cb29940f19a1464b8608f2cab8a8616aba75fd/numpy-2.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl(19.2MB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━19.2/19.2MB48.9MB/seta0:00:00Collectingpython-dateutil>=2.8.2(frompandas)Downloadinghttps://pypi.tuna.tsinghua.edu.cn/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl(229kB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━229.9/229.9kB41.3MB/seta0:00:00Collectingpytz>=2020.1(frompandas)Downloadinghttps://pypi.tuna.tsinghua.edu.cn/packages/9c/3d/a121f284241f08268b21359bd425f7d4825cffc5ac5cd0e1b3d82ffd2b10/pytz-2024.1-py2.py3-none-any.whl(505kB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━505.5/505.5kB52.4MB/seta0:00:00Collectingtzdata>=2022.7(frompandas)Downloadinghttps://pypi.tuna.tsinghua.edu.cn/packages/65/58/f9c9e6be752e9fcb8b6a0ee9fb87e6e7a1f6bcab2cdc73f02bb7ba91ada0/tzdata-2024.1-py2.py3-none-any.whl(345kB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━345.4/345.4kB50.4MB/seta0:00:00Collectingsix>=1.5(frompython-dateutil>=2.8.2->pandas)Downloadinghttps://pypi.tuna.tsinghua.edu.cn/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl(11kB)Installingcollectedpackages:pytz,tzdata,six,numpy,python-dateutil,pandasSuccessfullyinstallednumpy-2.0.1pandas-2.2.2python-dateutil-2.9.0.post0pytz-2024.1six-1.16.0tzdata-2024.1WARNING:Runningpipasthe'root'usercanresultinbrokenpermissionsandconflictingbehaviourwiththesystempackagemanager.Itisrecommendedtouseavirtualenvironmentinstead:https://pip.pypa.io/warnings/venv[notice]Anewreleaseofpipisavailable:23.2.1->24.2[notice]Toupdate,run:pip3install--upgradepip[root@node01admin]#pip3list|greppandaspandas2.2.2[notice]Anewreleaseofpipisavailable:23.2.1->24.2[notice]Toupdate,run:pip3install--upgradepip[root@node01admin]#python3-c"importpandasaspd;print(pd.__version__);df=pd.DataFrame({'A':[1,2,3],'B':[4,5,6]});print(df)"2.2.2AB014125236这样就能很快解决了! 另外还有一点就是在CentOS系统中,如果同时安装了Python2和Python3,默认情况下,yum 和其他基于Python的系统工具(如 rpm、dnf 等)通常会使用Python2。这是因为这些工具的脚本头(shebang)通常会指定为 #!/usr/bin/python 或 #!/usr/bin/python2。 所以如果咱们将系统的默认Python版本更改为Python3(sudoln-sf/usr/bin/python3/usr/bin/python),那么 yum 和其他系统工具可能会因为找不到Python2而无法正常工作。为了避免这种情况,我们需要确保这些工具的脚本头指向Python2。方式也很简单:修改yum脚本头打开 /usr/bin/yum 文件,并将其第一行(shebang)修改为指向Python2:[root@node01admin]#sed-i'1s/^/#!\/usr\/bin\/python2\n/'/usr/bin/yum或者手动编辑 /usr/bin/yum 文件:[root@node01admin]#vi/usr/bin/yum将第一行修改为:#!/usr/bin/python2修改其他相关脚本类似地,如果我们需要修改其他基于Python的系统工具脚本,例如 /usr/libexec/urlgrabber-ext-down:[root@node01admin]#sed-i'1s/^/#!\/usr\/bin\/python2\n/'/usr/libexec/urlgrabber-ext-down或者手动编辑 /usr/libexec/urlgrabber-ext-down 文件:[root@node01admin]#vi/usr/libexec/urlgrabber-ext-down将第一行修改为:#!/usr/bin/python2验证修改修改完成后,验证 yum 是否正常工作:[root@node01admin]#yum--version3.4.3Installed:rpm-4.11.3-48.el7_9.x86_64at2024-08-0508:08Built:CentOSBuildSystemat2021-11-2416:33Committed:MichalDomonkosat2021-11-01Installed:yum-3.4.3-168.el7.centos.noarchat2024-08-0508:09Built:CentOSBuildSystemat2020-10-0117:03Committed:CentOSSourcesat2020-09-29Installed:yum-plugin-fastestmirror-1.1.31-54.el7_8.noarchat2020-12-2302:28Built:CentOSBuildSystemat2020-05-1216:27Committed:MichalDomonkosat2020-03-12如果 yum 正常工作,说明修改成功。三、卸载Python3最后附上一个简单的卸载操作"三部走":1、使用rpm卸载python3[root@node01admin]#rpm-qa|greppython3|xargsrpm-ev--allmatches--nodeps 2、删除所有残余文件[root@node01admin]#whereispython3|xargsrm-frv3、查看现有安装的python,验证是否删除干净[root@node01admin]#whereispython3
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 会员注册

本版积分规则

QQ|手机版|心飞设计-版权所有:微度网络信息技术服务中心 ( 鲁ICP备17032091号-12 )|网站地图

GMT+8, 2024-12-26 23:00 , Processed in 0.846596 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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