Linux下python3.x安装,之前没有写下来,这次完整记录下
使用Centos7为例,其他的大同小异
先安装依赖,避免后面有模块不能导入问题
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo #此包不装,python解释器里面用不了删除键等 yum install readline-devel -y #安装python3前最好先安装好openssl,不然使用中会提示没有ssl模块: yum install openssl openssl-devel -y #或者源码编译安装最其他版本的openssl,yum安装的版本比较早了 #Python3添加支持ssl模块 :https://me.jinchuang.org/archives/584.html #其他的包(安装这么多是为了后面使用不会缺少各种模块) yum install gcc gcc-c++ zlib-devel libuuid-devel ncurses-devel \ sqlite-devel tkinter libuuid-devel pcre-devel libffi-devel libpcap-devel \ tk-devel tcl-devel python-sqlite3dbm gdbm-devel db4-devel xz-devel bzip2-devel -y
下载python3.8 源码包 Python Download
#解压安装 tar xf Python-3.8.2.tgz cd Python-3.8.2 # --enable-shared 启用共享,方便其他依赖python的一些内置库(比如 mysqlclient) 的资源的正常安装 # --enable-optimizations 是优化选项(LTO,PGO等)加上这个flag编译后,性能有10%左右的优化,但是编译时间较久 ./configure --prefix=/usr/local/python38 --enable-shared #make这里可以使用make test查看缺少什么模块,不过非常耗时间 make && make install
配置环境变量生效
echo 'export PATH=$PATH:/usr/local/python38/bin' >>/etc/profile && source /etc/profile #添加动态链接库(不添加会报错libpython3.8.so.1.0) echo '/usr/local/python38/lib' >>/etc/ld.so.conf && ldconfig
确认版本
[root@localhost ~]# which python3 /usr/local/python38/bin/python3 [root@localhost ~]# python3 -V Python 3.8.2 #pip3版本 [root@localhost ~]# pip3 -V pip 19.2.3 from /usr/local/python38/lib/python3.8/site-packages/pip (python 3.8) [root@localhost ~]# python3 Python 3.8.2 (default, May 3 2020, 08:12:25) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> print (sys.version) 3.8.2 (default, May 3 2020, 08:12:25) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] >>>
本文最后记录时间 2024-03-30
文章链接地址:https://wojc.cn/archives/549.html
本站文章除注明[转载|引用|来源],均为本站原创内容,转载前请注明出处
文章链接地址:https://wojc.cn/archives/549.html
本站文章除注明[转载|引用|来源],均为本站原创内容,转载前请注明出处