【Python学习】Linux下编译安装Python

1、下载Python-3.6.5安装包

  在Python官网(https://www.python.org/downloads/)下载对应的安装包,选择3.6.5的linux版本,如下图:

  

2、将安装包上传至Linux服务器

  在Linux服务器根目录下创建目录package,并将安装包上传至该目录下

3、解压Python-3.6.5.tgz

  [root@Cherry /]# cd /package/

  [root@Cherry package]# tar -zxvf Python-3.6.5.tgz

4、创建Python-3.6.5安装目录

  [root@Cherry package]# mkdir /usr/local/python3

5、安装依赖包

  [root@Cherry package]# yum install -y gcc

  [root@Cherry package]# yum install -y zlib*

  [root@Cherry package]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel  #确保pip的时候不会出错

6、配置安装路径

  [root@Cherry package]# cd Python-3.6.5

  [root@Cherry Python-3.6.5]# ./configure --prefix=/usr/local/python3 --with-ssl

7、编译

  [root@Cherry Python-3.6.5]# make

8、安装

  [root@Cherry Python-3.6.5]# make install

9、建立软链接

  [root@Cherry Python-3.6.5]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3

  [root@Cherry Python-3.6.5]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

10、增加环境变量

  修改配置文件/etc/profile,增加以下内容:

  PATH=$PATH:$HOME/bin:

  PATH=$PATH:$HOME/bin:/usr/local/python3/bin

  执行语句source /etc/profile使环境变量配置立即生效

11、测试安装是否成功

  [root@Cherry Python-3.6.5]# python3
  Python 3.6.5 (default, Jun 28 2018, 12:12:14)
  [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>>

12、测试pip是否能使用

posted @ 2020-04-16 17:34  gtea  阅读(441)  评论(0编辑  收藏  举报