Python3 源码安装(linux)

一、源码安装

1.安装基础环境

yum -y install  zlib-devel bzip2-devel openssl-devel  sqlite-devel readline-devel  make

2.下载源码包

wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tar.xz

3.解压安装,并进入文件目录

  1. tar -xf Python-3.6.7.tar.xz
    
    cd Python-3.6.7/

4.修改配置文件

sed -ri 's/^#readline/readline/' Modules/Setup.dist

sed -ri 's/^#(SSL=)/\1/' Modules/Setup.dist

sed -ri 's/^#(_ssl)/\1/' Modules/Setup.dist

sed -ri 's/^#([\t]*-DUSE)/\1/' Modules/Setup.dist

sed -ri 's/^#([\t]*-L\$\(SSL\))/\1/' Modules/Setup.dist

5.开始编译安装

./configure --enable-shared

make -j 2 && make install

# -j cpu核心数 指定cpu核心数,会加快编译

二、配置共享库文件

1.为所有用户设置共享库目录

用vim 编辑器打开配置文件 /etc/profile.d/python3_lib.sh

vim /etc/profile.d/python3_lib.sh

在文件中加入以下内容:

# python3.6 共享库目录

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/bin

继续编辑文件 /etc/ld.so.conf.d/python3.conf 内容如下

/usr/local/bin

执行命令 加载配置

ldconfig

执行如下命令,使环境变量生效

  1. source /etc/profile

  2. #此条命令只能使本shell生效,若要使子shell生效,需要重启机器

测试python

[root@localhost tmp]# python3

Python 3.6.7 (default, Dec 24 2018, 10:42:15)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> print ('hello world')

hello world

>>> exit()

测试 pip3

[root@localhost tmp]# pip3 -V

pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
发布了9 篇原创文章 · 获赞 459 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/songhait/article/details/96299539